Solved

can I store an xsd file in an app.config file?  If so, how

Posted on 2010-08-18
3
466 Views
Last Modified: 2013-12-17
How can I store an xsd file in my app.config file (since it is xml)?  Also, how do I read it out?

Also, I am using this code to validate my xml.  How could I do that if I was using an app.config file since I will now have a file instead of a path for the "schemaFileName" argument.

                XmlSchemaSet sc = new XmlSchemaSet();
                sc.Add(targetNamespace, schemaFileName);

                XmlReaderSettings settings = new XmlReaderSettings();
                settings.Schemas = sc;
                settings.ValidationType = ValidationType.Schema;
0
Comment
Question by:jackjohnson44
  • 2
3 Comments
 
LVL 23

Expert Comment

by:Jens Fiederer
ID: 33466783
One method would be to encode it as a string - the Uri class has encode/decode functions available you could use.....this method sacrifices readability, though, and requires the encode to be done outside of your app to get it in....
0
 
LVL 23

Expert Comment

by:Jens Fiederer
ID: 33466890
A more readable possibility would be to roll your own config section, and include the xsd or xsds as part of it...this would require you to implement a class derived from ConfigurationSection to deal with it.
0
 
LVL 3

Accepted Solution

by:
GoJoeIsBlue earned 500 total points
ID: 33467812
If you are using "Visual Studio 2008" or "Visual Studio 2010" this is pretty easy, just do this:
1) Open your XSD-file
2) Select all content and copy
3) Right-click your project-file in Visual Studio's Solution Explorer and select "Properties" (located at the bottom)
4) Click the "Settings" tab in the properties window.
5) If all you see is a link, click the link and proceed
6) You a now precented with a grid consisting of the columns: Name, Type, Scope and Value
7) In "Name" type what ever you like your application setting to be called, eg. "MyXSD"
8) In "Type" choose "string", this should be the default choice
9) In "Scope" choose "User" if you plan to change the setting programatically, otherwise choose "Application"
10) In "Value" - paste your copied XSD-content
11) Hit CTRL+S which saves the settings

The above enables you to reach your settings like this:
string xsd = Properties.Settings.Default.MyXSD;

And  if your chose "User" as scope you can also do this:
Properties.Settings.Default.MyXSD = "<xs:schema ....> ... </xs:schema>";
Properties.Settings.Default.Save();
0

Featured Post

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question