write a file to a xml file 
Author Message
 write a file to a xml file

hi all,

is there a special way to include a file into a xml file. Eg: small sound
clip into innertext of a xml node.

any help apreciated.

rgds,

CMA



Fri, 20 May 2005 16:56:13 GMT  
 write a file to a xml file
You would need to encode the file into Base64.
This can be achieved by calling Convert.ToBase64String() and passing in the
byte array that contains the file.
example code would be like(taken from msdn library):
public void EncodeWithString() {
    System.IO.FileStream inFile;
    byte[]                 binaryData;

    try {
        inFile = new System.IO.FileStream(inputFileName,
                                          System.IO.FileMode.Open,
                                          System.IO.FileAccess.Read);
        binaryData = new Byte[inFile.Length];
        long bytesRead = inFile.Read(binaryData, 0,
                                    (int)inFile.Length);
        inFile.Close();
    }
    catch (System.Exception exp) {
        // Error creating stream or reading from it.
        System.Console.WriteLine("{0}", exp.Message);
        return;
    }

    // Convert the binary input into Base64 UUEncoded output.
    string base64String;
    try {
         base64String =
            System.Convert.ToBase64String(binaryData,
                                          0,
                                          binaryData.Length);
    }
    catch (System.ArgumentNullException) {
        System.Console.WriteLine("Binary data array is null.");
        return;
    }

    // Write the UUEncoded version to the output file.
    System.IO.StreamWriter outFile;
    try {
        outFile = new System.IO.StreamWriter(outputFileName,
                                    false,
                                    System.Text.Encoding.ASCII);
        outFile.Write(base64String);
        outFile.Close();
    }
    catch (System.Exception exp) {
        // Error creating stream or writing to it.
        System.Console.WriteLine("{0}", exp.Message);
    }

Quote:
}



Quote:
> hi all,

> is there a special way to include a file into a xml file. Eg: small sound
> clip into innertext of a xml node.

> any help apreciated.

> rgds,

> CMA



Fri, 20 May 2005 17:09:37 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. How to write control properties to XML file

2. A beginner in C#....about writing XML files

3. Writing encrypted data into a XML file

4. writing long, double to xml file

5. Writing XML file, parsing...

6. read and write xml files

7. creating xml schema programmatically from an an xml file without using ADO.NET

8. VC++ and XML, I want to retrieve an XML file from URL

9. VC++ and XML, I want to retrieve an XML file from a URL

10. how to: XML file as application configuration file

11. starting MSIE out of Visual C++ with parameters: XML file and XSL file

12. starting MSIE out of Visual C++ with parameters: XML file and XSL file

 

 
Powered by phpBB® Forum Software