how to load xml files stored in the resources of a project

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • rizwanahmed24@gmail.com

    #1

    how to load xml files stored in the resources of a project

    Hi

    i have created a project that contains some class files and xml files
    stored in resources. i have created dll of this project and am using
    it in another project.

    In other project i want to read the xml stored in the resources of
    loaded project. Please tell me how can i extract xml file from the
    resources of the loaded project (in dll).

    Regards
    Rizwan

  • Ignacio Machin \( .NET/ C# MVP \)

    #2
    Re: how to load xml files stored in the resources of a project

    Hi,

    <rizwanahmed24@ gmail.comwrote in message
    news:1183983765 .975079.254130@ n2g2000hse.goog legroups.com...
    Hi
    >
    i have created a project that contains some class files and xml files
    stored in resources. i have created dll of this project and am using
    it in another project.
    >
    In other project i want to read the xml stored in the resources of
    loaded project. Please tell me how can i extract xml file from the
    resources of the loaded project (in dll).
    static string ExtractResource ( string resourceName)
    {
    //look for the resource name
    foreach( string currentResource in
    System.Reflecti on.Assembly.Get ExecutingAssemb ly().GetManifes tResourceNames( ­)
    )
    if ( currentResource .LastIndexOf( resourceName) != -1 )
    {
    string fqnTempFile = System.IO.Path. GetTempFileName ();
    string path = System.IO.Path. GetDirectoryNam e( fqnTempFile);
    string rootName= System.IO.Path. GetFileNameWith outExtension(
    fqnTempFile);
    string destFile = path + @"\" + rootName + "." +
    System.IO.Path. GetExtension( currentResource );

    System.IO.Strea m fs =
    System.Reflecti on.Assembly.Get ExecutingAssemb ly().GetManifes tResourceStream ­(
    currentResource );


    byte[] buff = new byte[ fs.Length ];
    fs.Read( buff, 0, (int)fs.Length) ;
    fs.Close();


    System.IO.FileS tream destStream = new System.IO.FileS tream ( destFile,
    FileMode.Create );
    destStream.Writ e( buff, 0, buff.Length);
    destStream.Clos e();


    return destFile;
    }


    throw new Exception("Reso urce not found : " + resourceName);


    }



    Comment

    Working...