473,657 Members | 2,507 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to write data to an embedded resource

I have embedded resource called Settings.xml. I'm able to read the resource but how can I write data to the resource. The code for read operation follows:

private XmlDocument m_doc = new XmlDocument();

System.Reflecti on.Assembly a = System.Reflecti on.Assembly.Get ExecutingAssemb ly();
System.IO.Strea m stream = a.GetManifestRe sourceStream(th is.GetType(),"S ettings.xml");
if(!(null==stre am))
{
System.IO.Strea mReader rdr = new StreamReader(st ream);
m_doc.Load(rdr) ;
stream.Close();
rdr.Close();
}

Now, if I make changes to m_doc and want to save them to embedded resource, I try like this:

System.Reflecti on.Assembly a = System.Reflecti on.Assembly.Get ExecutingAssemb ly();
Stream stream = a.GetManifestRe sourceStream(th is.GetType(),"S ettings.xml");
m_doc.Save(stre am);
stream.Close();

This raises exception, however: "Stream is not writable." What am I doing wrong?
Nov 15 '05 #1
2 12117
AFAIK, embedded resources are read-only and cannot be written to.

"Jani Mantytorma" <an*******@disc ussions.microso ft.com> wrote in message
news:BC******** *************** ***********@mic rosoft.com...
I have embedded resource called Settings.xml. I'm able to read the resource but how can I write data to the resource. The code for read
operation follows:
private XmlDocument m_doc = new XmlDocument();

System.Reflecti on.Assembly a = System.Reflecti on.Assembly.Get ExecutingAssemb ly(); System.IO.Strea m stream = a.GetManifestRe sourceStream(th is.GetType(),"S ettings.xml"); if(!(null==stre am))
{
System.IO.Strea mReader rdr = new StreamReader(st ream);
m_doc.Load(rdr) ;
stream.Close();
rdr.Close();
}

Now, if I make changes to m_doc and want to save them to embedded resource, I try like this:
System.Reflecti on.Assembly a = System.Reflecti on.Assembly.Get ExecutingAssemb ly(); Stream stream = a.GetManifestRe sourceStream(th is.GetType(),"S ettings.xml"); m_doc.Save(stre am);
stream.Close();

This raises exception, however: "Stream is not writable." What am I doing

wrong?
Nov 15 '05 #2
Thanks for your reply. I slept over night and thought that this could be a
reason. And now you confirmed that.

Now I'm wondering why this (read-only) is not emphasized in the MSDN and in
tutorials. But, indirectly they say it: there are no examples of writing to
an embedded resource.

Embedding a resource file would have been very handy if writing had been
allowed.

"Ed Courtenay" <my***********@ edcourtenay.co. uk> wrote in message
news:%2******** *******@TK2MSFT NGP11.phx.gbl.. .
AFAIK, embedded resources are read-only and cannot be written to.

Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3081
by: DC Gringo | last post by:
I have some code that writes log entries upon errors in an VB.NET web app. I can write the Message but in the log, preceding my message is the following: Description: The description for Event ID ( 0 ) in Source ( Application ) cannot be found. The local computer may not have the necessary registry information or message DLL files to display messages from a remote computer. You may be able to use the /AUXSOURCE= flag to retrieve this...
15
3309
by: Viviana Vc | last post by:
How can I programatically do the equivalent of the following: cacls "C:\Program Files\test" /T /G Everyone:f ? Thanks, Viv
1
1774
by: Ola Theander | last post by:
Dear subscribers I'm currently creating a small application that will run at the end of a web installation to configure a SQL Server. For this task I have a SQL batch file in the same format as SQL Query Analyzer uses. I would prefer not to merge the content of this file into the source code of configuration application but instead keep the SQL commands in a text file included in the executable, pretty much like resource data, for...
18
3691
by: jacob navia | last post by:
In C, we have read-only memory (const), read/write memory (normal data), and write only memory. Let's look at the third one in more detail. Write only memory is a piece of RAM that can only be written to, since its contents are undefined. The program is allocating a new piece of data, and the previous contents aren't relevant. This memory
5
8221
by: Drew | last post by:
Assembly asm = Assembly.GetExecutingAssembly(); me = new Bitmap(asm.GetManifestResourceStream("me.gif")); I have used this before without any problem, but now I get: An unhandled exception of type 'System.ArgumentException' occurred in system.drawing.dll Additional information: 'null' is not a valid value for 'stream'.
1
2935
by: n! | last post by:
I have an irritating problem with VS.NET2003, C#. I wrote some code that would build my application menu from an XML resource file. Purely to make it easy for me to edit, so I've added this file as an embedded resource. My irritation, is that when I update the resource file and nothing else. VS does not build the project with the newly edited resource file. So if I run the application again, it actually hasn't been updated to use my newly...
0
2190
by: Johann Blake | last post by:
I'm having trouble grasping how ASP.NET correctly locates resources. There is plenty of documentation on this subject but some things are not clear at all. In my ASP.NET application, I have multiple web forms. When you compile the application, it creates a DLL. If you view this DLL using ILDASM (the manifest), it shows info about the resources stored in the DLL. There is essentially an embedded resource "section" for each web form. The...
4
4403
by: Jason Pettys | last post by:
In an ASP.NET project I am setting the content type of my .ascx and ..aspx files to Embedded Resource for a separate reason. When I do this they get embedded as "RootNamespace.Filename" but I would like them to be embedded as "RootNamespace.Folder.Filename". I see that the .resources files are embedded with the containing folder information in the namespace, and I think c# projects work this way, too. Is there any way (a vbc command...
1
3138
by: Claire | last post by:
Ive written a small string resource building utility that I send out to our translators. I have a setup project for each language we support, which picks out a group of 12 english resx files plus their paired "foreign" resx for that language only and installs those resource files in a subdirectory somewhere. I'm trying to create a setup project in visual studio 2008. Ive got my Application Folder set up with my executable. Im now...
0
8305
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8825
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8732
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7324
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6163
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4151
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4302
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1611
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.