Welcome to Dream.In.Code
Click Here
Getting C# Help is Easy!

Join 118,485 C# Programmers for FREE! Ask your question and get quick answers from experts. There are 950 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



How to reference an XML schema file in my project

 
Reply to this topicStart new topic

How to reference an XML schema file in my project

KyleG
post 18 Jul, 2008 - 08:22 AM
Post #1


New D.I.C Head

*
Joined: 11 Jun, 2008
Posts: 41



Thanked 1 times
My Contributions


I have an XML schema file (.xsd) that I'm using for validation. I've added it to my project for source control purposes. Initially I added it as a resource and referenced it in the code as ProjectNamespace.Properties.Resources.SchemaFile (which returned a string), but I ran into some quirks with Vault (source control) not seeing that I had checked it out. I want to be able to reference the file in code without having to actually deploy the file to the client's machine (i.e. I don't want issues if they delete the file). So I've added the schema file to the project like all of my source files and set the build action to "Content". Is this right? How do I go about referencing the file if it's not in the build directory, or anywhere on the disk?
User is offlineProfile CardPM

Go to the top of the page


KyleG
post 18 Jul, 2008 - 09:46 AM
Post #2


New D.I.C Head

*
Joined: 11 Jun, 2008
Posts: 41



Thanked 1 times
My Contributions


Well I figured it out.

I added the file to the project and set its Build Action to Embedded Resource. Then I used this code to access it:
csharp

using System.Reflection;
using (StreamReader reader = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("MyNamespace.SchemaFileName.xsd"))) {
...
}


I had to use the Assembly.GetExecutingAssembly().GetManifestResourceNames() method to find out that I needed the project's namespace prefixing the file.
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 10/11/08 06:18AM

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month