// Parse the filename out of the complete path in .NET framework

Draw QR Code in .NET framework // Parse the filename out of the complete path

// Parse the filename out of the complete path
QR Code JIS X 0510 Encoder In .NET Framework
Using Barcode generation for ASP.NET Control to generate, create QR Code image in ASP.NET applications.
www.OnBarcode.com
Paint Bar Code In Visual Studio .NET
Using Barcode creator for ASP.NET Control to generate, create bar code image in ASP.NET applications.
www.OnBarcode.com
// and assign it to the parameter.
Printing QR Code In Visual C#.NET
Using Barcode generation for .NET Control to generate, create QR Code image in .NET applications.
www.OnBarcode.com
QR Code Encoder In .NET Framework
Using Barcode drawer for Visual Studio .NET Control to generate, create QR-Code image in Visual Studio .NET applications.
www.OnBarcode.com
FileNameParameter.Value = CompleteFilePath.Substring _
Encode QR In VB.NET
Using Barcode maker for .NET framework Control to generate, create QR image in Visual Studio .NET applications.
www.OnBarcode.com
Code-39 Generator In VS .NET
Using Barcode encoder for ASP.NET Control to generate, create Code 39 Full ASCII image in ASP.NET applications.
www.OnBarcode.com
(CompleteFilePath.LastIndexOf("\\")+ 1); // Set the DocumentFile parameteter to the BLOB Value.
Matrix 2D Barcode Drawer In VS .NET
Using Barcode drawer for ASP.NET Control to generate, create 2D Barcode image in ASP.NET applications.
www.OnBarcode.com
Print DataMatrix In VS .NET
Using Barcode drawer for ASP.NET Control to generate, create Data Matrix 2d barcode image in ASP.NET applications.
www.OnBarcode.com
DocumentFileParameter.Value = BLOB;
PDF-417 2d Barcode Maker In VS .NET
Using Barcode drawer for ASP.NET Control to generate, create PDF 417 image in ASP.NET applications.
www.OnBarcode.com
Painting Bar Code In VS .NET
Using Barcode drawer for ASP.NET Control to generate, create barcode image in ASP.NET applications.
www.OnBarcode.com
Lesson 3: Saving and Retrieving BLOB Values in a Database
GS1 - 12 Generator In VS .NET
Using Barcode generation for ASP.NET Control to generate, create UPC-A image in ASP.NET applications.
www.OnBarcode.com
Leitcode Maker In .NET Framework
Using Barcode encoder for ASP.NET Control to generate, create Leitcode image in ASP.NET applications.
www.OnBarcode.com
// Execute the command and save the BLOB to the database.
Code 128 Creation In Java
Using Barcode printer for Java Control to generate, create Code128 image in Java applications.
www.OnBarcode.com
Code 128 Code Set B Maker In Objective-C
Using Barcode printer for iPad Control to generate, create Code 128 Code Set C image in iPad applications.
www.OnBarcode.com
SaveDocCommand.Connection.Open();
Code 39 Extended Recognizer In VB.NET
Using Barcode reader for .NET Control to read, scan read, scan image in .NET applications.
www.OnBarcode.com
Bar Code Decoder In VB.NET
Using Barcode scanner for .NET framework Control to read, scan read, scan image in .NET applications.
www.OnBarcode.com
SaveDocCommand.ExecuteNonQuery();
Create Barcode In VB.NET
Using Barcode creation for .NET framework Control to generate, create barcode image in .NET applications.
www.OnBarcode.com
UCC - 12 Creation In Java
Using Barcode creation for Java Control to generate, create EAN128 image in Java applications.
www.OnBarcode.com
MessageBox.Show(FileNameParameter.Value.ToString() + " saved to database.", _
Code 128 Code Set B Creation In None
Using Barcode drawer for Office Word Control to generate, create Code 128B image in Microsoft Word applications.
www.OnBarcode.com
Code 39 Full ASCII Printer In C#
Using Barcode drawer for Visual Studio .NET Control to generate, create Code39 image in .NET framework applications.
www.OnBarcode.com
"BLOB Saved!", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show(ex.Message, "Save Failed", MessageBoxButtons.OK, _ MessageBoxIcon.Error);
finally
SaveDocCommand.Connection.Close();
9. Add the following code to retrieve the BLOB from the database and write it back out as a file:
' VB Private Sub FetchBlobFromDatabase() ' Verify there is a BLOB selected to retrieve. If BlobList.Text = "" Then
MessageBox.Show("Select a BLOB to fetch from the ComboBox")
Exit Sub
End If ' Get the path to save the BLOB to.
GetSavePath()
' Create the Command object to fetch the selected BLOB. Dim GetBlobCommand As New SqlCommand("SELECT FileName, DocumentFile " & _ "FROM DocumentStorage " & _ "WHERE FileName = @DocName", NorthwindConnection) GetBlobCommand.Parameters.Add("@DocName", SqlDbType.NVarChar).Value = _ BlobList.Text
' Current index to write the bytes to
Dim CurrentIndex As Long = 0
' number of bytes to store in the BLOB.
Dim BufferSize As Integer = 100
' Actual number of bytes returned when calling GetBytes.
Dim BytesReturned As Long
' The Byte array used to hold the buffer.
Dim Blob(BufferSize - 1) As Byte
6
Working with Data in a Connected Environment
GetBlobCommand.Connection.Open() Dim reader As SqlDataReader = _ GetBlobCommand.ExecuteReader(CommandBehavior.SequentialAccess) Do While reader.Read ' Create or open the selected file. Dim FileStream As New IO.FileStream(SavePath & "\" & _ reader("FileName").ToString, IO.FileMode.OpenOrCreate, IO.FileAccess.Write) ' Set the writer to write the BLOB to the file. Dim writer As New IO.BinaryWriter(FileStream) ' Reset the index to the beginning of the file. CurrentIndex = 0 ' Set the BytesReturned to the actual number of bytes returned by the GetBytes call. BytesReturned = reader.GetBytes(1, CurrentIndex, Blob, 0, BufferSize) ' If the BytesReturned fills the buffer keep appending to the file. Do While BytesReturned = BufferSize writer.Write(Blob) writer.Flush() CurrentIndex += BufferSize BytesReturned = reader.GetBytes(1, CurrentIndex, Blob, 0, BufferSize) Loop ' When the BytesReturned no longer fills the buffer, write the remaining bytes.
writer.Write(Blob, 0, CInt(BytesReturned - 1))
writer.Flush()
writer.Close()
FileStream.Close()
Loop
reader.Close()
GetBlobCommand.Connection.Close()
End Sub
// C# private void FetchBlobFromDatabase() {
// Verify there is a BLOB selected to retrieve.
if (BlobList.Text == "")
MessageBox.Show("Select a BLOB to fetch from the ComboBox"); return; }
// Get the path to save the BLOB to.
Lesson 3: Saving and Retrieving BLOB Values in a Database
GetSavePath(); // Create the Command object to fetch the selected BLOB. SqlCommand GetBlobCommand = new SqlCommand("SELECT FileName, DocumentFile " + "FROM DocumentStorage " + "WHERE FileName = @DocName", NorthwindConnection); GetBlobCommand.Parameters.Add("@DocName", SqlDbType.NVarChar).Value = BlobList.Text; // Current index to write the bytes to.
long CurrentIndex = 0;
// number of bytes to store in the BLOB.
int BufferSize = 100;
// Actual number of bytes returned when calling GetBytes.
long BytesReturned ;
// The Byte array used to hold the buffer.
byte[] Blob = new byte[BufferSize];
GetBlobCommand.Connection.Open(); SqlDataReader reader = GetBlobCommand.ExecuteReader(CommandBehavior.SequentialAccess); while(reader.Read()) { // Create or open the selected file. System.IO.FileStream FileStream = new System.IO.FileStream(SavePath + "\\" + _ reader["FileName"].ToString(), System.IO.FileMode.OpenOrCreate, _ System.IO.FileAccess.Write); // Set the writer to write the BLOB to the file. System.IO.BinaryWriter writer= new System.IO.BinaryWriter(FileStream); // Reset the index to the beginning of the file.
CurrentIndex = 0;
// Set the BytesReturned to the actual number
// of bytes returned by the GetBytes call.
BytesReturned = reader.GetBytes(1, CurrentIndex, Blob, 0, BufferSize);
// If the BytesReturned fills the buffer keep appending to the file.
while (BytesReturned == BufferSize)
writer.Write(Blob);
writer.Flush();
CurrentIndex += BufferSize; BytesReturned = reader.GetBytes(1, CurrentIndex, Blob, 0, BufferSize); }
6
Working with Data in a Connected Environment
// When the BytesReturned no longer fills the buffer, write the remaining bytes. writer.Write(Blob, 0, (int)(BytesReturned)); writer.Flush(); writer.Close(); FileStream.Close();
reader.Close();
GetBlobCommand.Connection.Close();
10. Double-click each of the three buttons to create the button-click event handlers and add the following code to the form:
' VB Private Sub SaveBlobButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)_ Handles SaveBlobButton.Click SaveBlobToDatabase() End Sub Private Sub FetchBlobButton_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs)_ Handles FetchBlobButton.Click FetchBlobFromDatabase()
End Sub
Private Sub RefreshBlobListButton_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles RefreshBlobListButton.Click refreshBlobList() End Sub // C# private void RefreshBlobListButton_Click(object sender, EventArgs e) { RefreshBlobList(); } private void SaveBlobButton_Click(object sender, EventArgs e) { SaveBlobToDatabase(); } private void FetchBlobButton_Click(object sender, EventArgs e) { FetchBlobFromDatabase(); }
11. Run the application. When the application starts, you have the option of creating the table that stores the BLOB values. If you select Yes, the table is created, replac ing any existing DocumentStorage table with a new one.
Lesson 3: Saving and Retrieving BLOB Values in a Database
CAUTION
Existing DocumentStorage Table in your database
If you already have a DocumentStorage table in your database and select Yes to create one, the existing table is dropped along with any records it may contain.
12. Click the Save BLOB to Database button and navigate to any Microsoft Office Word document on your hard drive. As soon as you select a file, it is saved to the database and a confirmation message appears. 13. Click the Refresh List button, and the file you just saved appears in the combo box. 14. Now click the Fetch BLOB from Database button and select a folder to save the file (BLOB data) out to.
Copyright © OnBarcode.com . All rights reserved.