"Merge" two xml files into one file stream then deserialize

"Merge" two xml files into one file stream then deserialize


I have two config files:

1. "dbs.config" which contains the connection string to a dbs.
2. "acc.config" will contain other settings

These have to be in two seperate config files it is not possible to have them in the same file


The code below will load one of the files (dbs.Config) into a file stream and then we used
 the Deserialize method to retrieve the oject state ie the "ConnectionString" and "HasEamil" (other config files my have more!)


What I want to be able to do is to load the second file (acc.config) into the same filestream before we use the deserialize method,
 so I can get the value of "DefaultUserID" as well as "HasEmail"

 


public static ModuleSettings GetSettings()
{
 HttpContext context = HttpContext.Current;

ModuleSettings data = (ModuleSettings)context.Cache["MyModule_Settings"];

XmlSerializer serializer = new XmlSerializer(typeof(ModuleSettings));


 string accConfig = HttpContext.Current.Server.MapPath("/config/acc.config");
string dbsConfig = HttpContext.Current.Server.MapPath("/config/dbs.config");


// create a filestream to read the XML document
FileStream fs = new FileStream(dbsConfig, FileMode.Open);          

//need to somehow load accConfig into fs as well???????


// use the Deserialize method to retrieve the oject state
data = (ModuleSettings)serializer.Deserialize(fs);
fs.Close()

context.Cache.Insert("MyModule_Settings", data, new CacheDependency(fileName));

}


//module settings class
public class ModuleSettings
{
 private string connectionString;
 private string defaultUserID;
 private bool hasEmail;
 public ModuleSettings()
 { }  

 [XmlElement]   //this will come from dbs.config
 public string ConnectionString
 {
  get
  {return connectionString;}
  set
  {connectionString = value;}
 }
 
 [XmlElement]   //this will come from acc.config
 public string DefaultUserID
 {
  get
  {return defaultUserID;}
  set
  {defaultUserID= value;}
 }  
 public bool HasEmail
 {
  get
  {return hasEmail;}
  set
  {hasEmail= value;}
 }
}


//dbs.config
<?xml version="1.0"?>
<ModuleSettings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <ConnectionString>myConnectionString</ConnectionString>
</ModuleSettings>

//acc.config
<?xml version="1.0"?>
<ModuleSettings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <DefaultUserID>01</DefaultUserID>
  <HasEmail>01</HasEmail>
</ModuleSettings>

Any ideas would be great! Thanks

0
ricc
2/5/2008 4:46:09 PM
asp.net.xml-datasource 7181 articles. 0 followers. Follow

1 Replies
1226 Views

Similar Articles

[PageSpeed] 31

 Nah, I think you'd be better off by deserializing into two separate instances, which you then merge "manually" into a new ModuleSettings instance very easily.


-- "Mark As Answer" if my reply helped you --
0
gunteman
2/5/2008 5:36:24 PM
Reply:

Similar Artilces:

Is there a way to write Atlas "text/xml-script" script Into single file like ".js" or ".css" file
I have tried the following code: <script type="text/xml-script" src="Default.aspx.ajax"><script type="text/xml-script" src="Default.aspx.js"><script type="text/xml-script" src="Default.xml"> but they dit dot work. thanks.msn & email:lidong6@gmail.com I believe it does not work as the XML-Script processor takes the content within the script tags to do processing and ignores the src tag. I think this will be a nice feature to add in the next release....

"File" to "File$date"
Okay... Thanks for all your answers! From all, I combinded the perfext solution: rename("test.txt", "test" . &heute() . ".txt"); sub heute { return (localtime(time))[3] . (localtime(time))[4] . = ((localtime(time))[5] 1900); } Thanks ;) Andreas -----Urspr=FCngliche Nachricht----- Von: Sudarshan Raghavan [mailto:sraghav@india.hp.com]=20 Gesendet: Samstag, 14. September 2002 15:21 An: Perl beginners Betreff: Re: AW: Rename "File" to "File$date" On Sat, 14 Sep 2002, Sudarshan Raghavan wrote: >=20 > #!/...

how can i merge multiple xml files into one single xml file
hello i need to merge multiple xml files into a single xml file without losing the hierarchy of the xml document..... pls help regards shabari IS it really include or merge? Including is easy, merge - not. The complexity depends on your merge logic. Show us some samples.Oleg [XML MVP, MCPD]XmlLab.Net | http://blog.tkachenko.com...

datawindow.import(XML!,"file.xml") syntax error
I am using Pocket PowerBuilder 1.5 build 360 from the help file I saw [ImportFile method (DataWindows)] long dwcontrol.ImportFile ( {saveastype importtype}, string filename {, long startrow {, long endrow {, long startcolumn {, long endcolumn {, long dwstartcolumn } } } } } ) This statement inserts all the data in the file D:\TMP\EMPLOYEE.CSV into dw_employee starting at the first column: dw_employee.ImportFile("D:\TMP\EMPLOYEE.CSV") This statement inserts all the data in the file D:\TMP\EMPLOYEE.XML into dw_employee starting at the first column: dw_em...

Convert file on a path to "Stream" without the use of html "file" control
Hello, Basically I am building a CMS of sorts, I have built in the functionality to generate a thumbnail of an image that get's catalogued, I then take my original file and transfer it to the server along with the thumbnail - which is all working fine... Using the html file control accpets the following: (name - "fileImage") Dim x As Stream = fileImage.PostedFile.InputStream() Which is fine - one file at a time, however I need to build in the functionality to get all the image files from a directory and batch transfer them. basically I will have the path similar to:...

Rename "File" to "File$date"
Hy everybody in the List! I have a Problem writing a little perl application... Im a very newbie to programming and need your help :) The Problem is: I have a file "dev.txt" and I want to rename it once a day (with a = cronjob) like "dev13092002.txt" So i need to rename it with a date variable. All I have at the moment is: #!/usr/bin/perl $d =3D `date`; $d =3D /pattern1(pattern2)/; sytem("cp test.txt test`$d`.txt"); Does anyone of you know how to do that? THANKS in advance! =09 | Telematikzentrum D=FCrrwangen GmbH &am...

superreview granted: [Bug 219355] XML Parsing Error: undefined entity on files with Mime-Type: application/xhtml+xml, including about:, or "text/xml" : [Attachment 131594] use NS_GRE_DIR
Darin Fisher <darin@meer.net> has granted Benjamin Smedberg <bsmedberg@covad.net>'s request for superreview: Bug 219355: XML Parsing Error: undefined entity on files with Mime-Type: application/xhtml+xml, including about:, or "text/xml" http://bugzilla.mozilla.org/show_bug.cgi?id=219355 Attachment 131594: use NS_GRE_DIR http://bugzilla.mozilla.org/attachment.cgi?id=131594&action=edit ...

superreview requested: [Bug 219355] XML Parsing Error: undefined entity on files with Mime-Type: application/xhtml+xml, including about:, or "text/xml" : [Attachment 131594] use NS_GRE_DIR
Benjamin Smedberg <bsmedberg@covad.net> has asked Darin Fisher <darin@meer.net> for superreview: Bug 219355: XML Parsing Error: undefined entity on files with Mime-Type: application/xhtml+xml, including about:, or "text/xml" http://bugzilla.mozilla.org/show_bug.cgi?id=219355 Attachment 131594: use NS_GRE_DIR http://bugzilla.mozilla.org/attachment.cgi?id=131594&action=edit ...

Convert "xls" file to "txt" file
Hi, I hope someone can help. I need to convert an Excel spreadsheet to an ASCI text file, in order to import data into a datawindow. I want to try and avoid asking users to save their files as text files and there are issues surrounding the use of ODBC to link to Excel. I am currently able to view my Excel data by way of an OLE object but if I try "Getdata", only the first 72 rows are imported to a string or blob and then subsequently to the datawindow. So I am looking for an OLE function which will "save as" my file. Help would be greatly appeciated. ...

Shortcut Key for "File" -> "Save As File"
Hi all, We can save as DataWindow Object into .XML file through "File-> Save As File" option (after opening DataWindow Object in PB). Here I am unable to identify shortcut key for "Save As File", can any one tell me the shortcut key is available or not? if yes, could you please tell me the shortcut key for "Save As File" menu item. Advanced thanks for your help. -Siva On Feb 4, 7:45=A0pm, Siva Prasad <sivamc...@gmail.com> wrote: > Hi all, > > We can save as DataWindow Object into .XML file through "File-> Save > As...

Microsoft Chart control for .NET Framework about state management and serialization problem, it works OK with one XML file but fails with another XML file
I use Microsoft Chart control for .NET Framework , you can see details at http://blogs.msdn.com/alexgor/archive/2008/10/27/microsoft-chart-control-for-net-framework-released.aspx The Chart1 is load data from a xml and save to ViewStateData, so even if after I click Reload button, the chart1 still display OK! I'm very strange that the chart1 works well after click Reload button if it's loaded from Chart1.Serializer.Load(HttpContext.Current.Server.MapPath("~/Template/1.xml"));but chart1 don't display fter click Reload button if it's loaded from Chart1.Serializer.Loa...

Visual Studio 2005. "Quick Find", "Quick Replace", "Find in Files", "Replace in Files" functionality no longer works
Hello, I just run into problem that find functionality is no longer working in Visual Studio 2005. "Quick Find", "Quick Replace", "Find in Files", "Replace in Files" functionality no longer responds. These are necessary functions when build any website. Any solutions on how to fix this problem?Improving lifestyles for luxury pets: TheFabulousPet In Menu bar click Window -> Reset Window Layout. It solves the problem.Improving lifestyles for luxury pets: TheFabulousPet...

File write error on file "acct" in module "GWEACCT".
--____HHJZYVOOFXDLYDIWHUSF____ Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: base64 Content-Disposition: inline; modification-date="Tue, 24 Sep 2007 10:15:42 -0400" VGhlIG1vcm5pbmcgb2YgV2VkLiBTZXB0IDE5dGguIHdlIHN3aXRjaGVkIG91ciBHV0lBIG92ZXIg dG8gdmVyc2lvbiBHVzYuNSBTUDYgZnJvbSB2ZXJzaW9uIEdXNS41LiAgVGhlIG5leHQgbW9ybmlu ZyB3ZSBzdGFydGVkIGdldHRpbmcgdGhlIGZvbGxvd2luZyBlcnJvciBpbiBvdXIgR1dJQSBsb2cg ZmlsZTsNCg0KMDktMjAtMDcgMDg6MjI6MTAgMCBVbmtub3duLCBlcnJvciBjb2RlID0gODIxMA0K MDktMjAtMDcgMDg6MjI6MjEgMCBNU0cgNDAwIERlZmVycmVkIGRlbGl2ZXJ5IGZpbGUgbWVtb3J5 IGVy...

File write error on file "acct" in module "GWEACCT"
Getting this on GWIA 6.02 scrolling across the screen. Runs on a Win2ksp3 box. Searching TID's...... JG I'd probably whack most of the subdirs under gwia and let gwia rebuild. -- Michael J. Bell Novell Support Connection Volunteer Sysop Author of Guinevere (http://www.openhandhome.com) PLEASE: Do not e-mail me privately unless specifically asked. I'm a volunteer, not a Novell employee! All opinions and advice provided are MINE alone and NOT Novell's unless specifically identified as such. Novell does not officially monitor these forums. Enhance...

Web resources about - "Merge" two xml files into one file stream then deserialize - asp.net.xml-datasource

Resources last updated: 12/14/2015 12:19:53 PM