Solved

byte[] to file

Posted on 2011-09-26
2
216 Views
Last Modified: 2012-05-12
Hi all

Given the code below..
and given that <<Data>> is an XML file
How can I output/write the value to an xml file in a directory = @"C:\Inetpub\ftproot\Protocoll\Filename.xml";  

Thanks for your input
public class DownloadFile 
{ 
public byte[] Data; 
public String Filename; 
}

Open in new window

0
Comment
Question by:ZURINET
2 Comments
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 36598029

DataTable dt = new DataTable();
dt.Columns.Add("dabyte", byte);

dt.Rows.Add(Data)
 

dt.WriteXML("C:\dabytes.xml");

refer
http://www.daniweb.com/software-development/csharp/threads/60139
0
 
LVL 22

Accepted Solution

by:
pivar earned 300 total points
ID: 36598076
Hi,

If I understand you correct you already have the xml-file in a byte array and want to write that to file. In that case, try
(from http://www.digitalcoding.com/Code-Snippets/C-Sharp/C-Code-Snippet-Save-byte-array-to-file.html)

/peter

 /// <summary>
/// Function to save byte array to a file
/// </summary>
/// <param name="_FileName">File name to save byte array</param>
/// <param name="_ByteArray">Byte array to save to external file</param>
/// <returns>Return true if byte array save successfully, if not return false</returns>
public bool ByteArrayToFile(string _FileName, byte[] _ByteArray)
{
    try
    {
        // Open file for reading
        System.IO.FileStream _FileStream = new System.IO.FileStream(_FileName, System.IO.FileMode.Create, System.IO.FileAccess.Write);

        // Writes a block of bytes to this stream using data from a byte array.
        _FileStream.Write(_ByteArray, 0, _ByteArray.Length);

        // close file stream
        _FileStream.Close();

        return true;
    }
    catch (Exception _Exception)
    {
        // Error
        Console.WriteLine("Exception caught in process: {0}", _Exception.ToString());
    }

    // error occured, return false
    return false;
}

Open in new window

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

743 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now