Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

copy a binary file to another file not exist before

Posted on 2009-07-06
3
Medium Priority
?
335 Views
Last Modified: 2012-05-07
Hi expert,

In MySql database, I have a binary file name carrier.myd. Since I'll delete this content file, and write new content to this file. To do that, I want to back up my carrier.myd to another file name. If in case something is wrong, I can use this new file name to back up the old data.
In C#, how can I make copy of this carrier.myd to a non existed file name?

Thanks,
JT

0
Comment
Question by:jtran007
3 Comments
 
LVL 1

Accepted Solution

by:
vaibhav_dw earned 2000 total points
ID: 24791627
Hi JT

You can do something like as that provided in the code snippet.
I've assumed the path of the files. I've simply read and writen the binary files.

FileStream f = new FileStream("d://carrier.myd", FileMode.Open);
	long length = f.Length;
        FileStream fbackup = new FileStream("d://backup//carrier.myd", FileMode.Create);
        BinaryReader br = new BinaryReader(f); 
        BinaryWriter bwbackup = new BinaryWriter(fbackup);
 
        byte[] buffer = br.ReadBytes(int.Parse(length.ToString()));
        bwbackup.Write(buffer);
 
        f.Close();
        fbackup.Close();
        br.Close();
        bwbackup.Close();

Open in new window

0
 
LVL 5

Expert Comment

by:Pablissimo
ID: 24791890
Path.GetRandomFilename() will give you a random filename that you could use - the filename it generates will be incredibly unlikely to match any existing file in your directory.
0
 

Author Closing Comment

by:jtran007
ID: 31600453
Thks,
JT
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

927 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