PC Review


Reply
Thread Tools Rate Thread

How to add a ".txt" resources file

 
 
John Torville
Guest
Posts: n/a
 
      25th Aug 2006
Hi there,

Does anyone know how to add ".txt" resources file to a C# project in Visual
Studio. It should compile down to an embedded ".resources" file the same way
as a ".resx" file. Thanks.


 
Reply With Quote
 
 
 
 
Marc Gravell
Guest
Posts: n/a
 
      25th Aug 2006
Add the .txt file (e.g. Add -> New Item...), and change the build type
to "Embedded Resource". Note you will need to write the read code.

You can also do this by adding a text file, opening e.g. the default
resx, and dragging the text file into the resx designer; this will
compile from that text file *into* the resx, allowing slightly easier
access, but with slightly higher footprint (for the resx wrapper).

Marc

 
Reply With Quote
 
John Torville
Guest
Posts: n/a
 
      25th Aug 2006
"Marc Gravell" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Add the .txt file (e.g. Add -> New Item...), and change the build type
> to "Embedded Resource".


Thanks for your help. I already tried that however and all it does is add
the ".txt" file as an embedded resource. I need to compile it into a
".resources" file first however and add that file as the embedded resource.
If there's no built-in way to do this I'll manually compile it using
"resgen.exe" but I can't figure out how to do this (add the call in VS that
is). Any suggestions? Thanks.


 
Reply With Quote
 
=?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
Guest
Posts: n/a
 
      25th Aug 2006
John,
This is a very old code snippet, but it may help:

static void createResource()
{

// you could load your text file here and use that----
//using ResourceWriter allows us to write to binary *.resources files
ResourceWriter rw =new ResourceWriter("MyMessages.resources");
// add our string resources with name, value
rw.AddResource("1", "Signs point to yes.");
rw.AddResource("2", "Yes.");
rw.AddResource("3", "Reply hazy, try again. ");
rw.AddResource("4", "Without a doubt. ");
rw.AddResource("5", "My sources say no. ");
rw.AddResource("6", "As I see it, yes. ");
rw.AddResource("7", "You may rely on it.");
rw.AddResource("8", "Concentrate and ask again. ");
rw.AddResource("9", "Outlook not so good. ");
rw.AddResource("10", "It is decidedly so. ");
rw.AddResource("11", "Better not tell you now.");
rw.AddResource("12", "Very doubtful. ");
rw.AddResource("13", "Yes - definitely. ");
rw.AddResource("14", "It is certain.");
rw.AddResource("15", "Cannot predict now.");
rw.AddResource("16", "Most likely.");
rw.AddResource("17", "Ask again later.");
rw.AddResource("18", "My reply is no.");
rw.AddResource("19", "Outlook good.");
rw.AddResource("20", "Don't count on it.");
rw.AddResource("21", "Ask again later");
rw.AddResource("22", "Ask more later");
rw.AddResource("23", "Reply meainingless, ask again later");
rw.AddResource("24", "Should not predict now");
rw.AddResource("25", "More information later");
rw.AddResource("26", "Out to Lunch");
rw.AddResource("27", "Closed on Sundays");
rw.AddResource("28", "No chance in Hell");
rw.AddResource("29", "Do you have capslock on?");
rw.AddResource("30", "Did you log on to the domain?");
rw.AddResource("31", "What mail server are you using?");
rw.AddResource("32", "Have you tried rebooting?");
rw.AddResource("33", "Can you ping that server?");
rw.AddResource("34", "Is it plugged in?");
rw.AddResource("35", "Is the network light on at all?");
rw.AddResource("36", "What's your port number?");
rw.AddResource("37", "Did you leave your PC unlocked?");
//generate the resource
rw.Generate();
//close the resource file
rw.Close();
}
}

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com




"John Torville" wrote:

> Hi there,
>
> Does anyone know how to add ".txt" resources file to a C# project in Visual
> Studio. It should compile down to an embedded ".resources" file the same way
> as a ".resx" file. Thanks.
>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel 2007 - crashing with "not enough resources to display file completely" Dane Beko Microsoft Excel Discussion 2 19th Mar 2009 12:23 AM
error msg when opening file "out of memory or system resources". =?Utf-8?B?RGF2aWQgRG9kcw==?= Microsoft Outlook Discussion 0 12th Jun 2007 05:56 PM
" Failed to load resources from resource file, please check your setup " Scott McFadden Microsoft Dot NET Framework 0 1st Apr 2006 06:03 AM
Re: C# Very Odd Behavior - "failed to load resources from resource file" Celso V Leite Microsoft Dot NET Framework 0 6th Apr 2005 09:02 PM
C# Very Odd Behavior - "failed to load resources from resource file" bleedledeep Microsoft C# .NET 0 7th Feb 2005 09:21 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:40 AM.