Solved

copy a binary file to another file not exist before

Posted on 2009-07-06
3
319 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 500 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
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.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

706 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

20 Experts available now in Live!

Get 1:1 Help Now