Results 1 to 2 of 2

Thread: [RESOLVED] Resource files in VS2010

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Dunmow,Essex,England
    Posts
    898

    Resolved [RESOLVED] Resource files in VS2010

    Hi All,

    I have added an xsd to a resource file of my solution.

    I now want to get to the xsd file, but am having difficulty. When I added the file to the resource file, the Persistence type is set to Linked at compile time.

    My resource file is called Resources.resx and the xsd file resides physically in a subdirectory of the solution. The file is called RBGENERIC.xsd.

    So, my code so far looks like this:

    Code:
    string filePath = System.AppDomain.CurrentDomain.BaseDirectory.ToString();
                ResourceManager resourceManager = ResourceManager.CreateFileBasedResourceManager("Resources", filePath, null);
                string res = resourceManager.GetString("RBGENERIC");
    my code fails tring to set the res string with:

    Could not find any resources appropriate for the specified culture (or the neutral culture) on disk.
    baseName: Resources locationInfo: <null> fileName: Resources.resources


    I then want to add this to a Schema set in the form:

    Code:
     XmlSchemaSet sc = new XmlSchemaSet();
                sc.Add("http://www.mytargetname", res);
    I had this working fine using a path with the xsd being stored outside the project. But I now need to embed the xsd as a resource.

  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Dunmow,Essex,England
    Posts
    898

    Re: Resource files in VS2010

    Sorry guys, I was going the wrong way about it. I do not need an actual resource file, instead all I need to do is right mouse click on the file properties and select the build action and set it to Embedded Resource.

    Then my code becomes:
    Code:
    Assembly assembly = Assembly.GetExecutingAssembly();
                    Stream stream = assembly.GetManifestResourceStream("mynamespace,filename");
    
                    XmlSchema schema = XmlSchema.Read(stream, null);
                    XmlSchemaCollection schemas = new XmlSchemaCollection();
    
                    schemas.Add(schema);
               
                    XmlReader reader = new XmlTextReader(xml);
                    XmlValidatingReader validReader = new XmlValidatingReader(reader);
                    validReader.Schemas.Add(schemas);
                    validReader.ValidationEventHandler += new ValidationEventHandler(ValidationCallback);
                    while (validReader.Read()) ;
                    validReader.Close();

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width