Windows Develop Bookmark and Share   
 index > Windows Forms General > Display Binary as PDF
 

Display Binary as PDF

I have a web site that successfully uploads a PDF file and stores it in a varbinary(max) field.  All is good..

Now I would like to pull the binary out and save it locally from my WinForms application to later index in my document imaging system.

Any ideas on how to save the file locally from my WinForms app?

Thanks
SuperTal  Wednesday, October 07, 2009 2:03 PM

I'm assuming that you want to know about performing the actual save and not about getting the binary from the database. I'm making this assumption based on the perception that you have the wherewithal to put the data and therefore have the wherewithal to get the data out.

Here's the code to save the file to disk.

/// <summary>
/// Saves binary data from a database record to a path on the file system.
/// </summary>
/// <param name="recordId">
/// The identifier of the record whose binary data will be saved.
/// </param>
private void SaveFileLocal( long recordId )
{
	byte[] data = null;
	string filePath = string.Empty;
	string directoryPath = string.Empty;

	/**
	 * TODO: Get data from database, this sample assumes 
	 * you have data in the "data" variable and a full file path
	 * in the "filePath" variable.
	 **/

	if( data != null && !string.IsNullOrEmpty( filePath ) )
	{
		directoryPath = Path.GetDirectoryName( filePath );
		if( !Directory.Exists( directoryPath ) )
			Directory.CreateDirectory( directoryPath );

		File.WriteAllBytes( filePath, data );
	}
}



Hope this helps.


"There's a way to do it better - find it." - Thomas Edison
Derik Palacino  Wednesday, October 07, 2009 10:49 PM

You can use google to search for other answers

Custom Search

More Threads

• How to display data from database one after another in Timer tick event
• Need help
• call a form from another application
• DataSet and xml
• Creating sections in app.config on fly
• Trying to print
• How to read the entire barcode?
• Window.close not working from webbrowser control on a Form.
• Layering Opaque Panels & BringToFront() [code included] - Any Help Please?
• share violation access on files in windows