Extract blob data to file system - c#

I have large amount of files(approx 80000) stored into sql server database as BLOB. Now I have a situation where I need to export all those file in blob to IBM Filenet.
For that what I think that first I need to stream those existing blob data into file system and then I will use filenet for uploading those file into filenet server.
Now please help me writing a C# utility which will convert those huge blob data into corresponding files.

You can be Managing FILESTREAM Data by Using Win32 API.
This link contains C# code that loads BLOB into a variable in you C# code. Then you can save it with path, file name and extention derrived from DB as well. Here is a a small quote of code:
//Read the data from the FILESTREAM
//BLOB.
sqlFileStream.Seek(0L, SeekOrigin.Begin);
numBytes = sqlFileStream.Read(buffer, 0, buffer.Length);
string readData = unicode.GetString(buffer);
if (numBytes != 0)
Console.WriteLine(readData);
See also Using FILESTREAM Storage in Client Applications.

Related

Upload to ADLS from file stream

I am making a custom activity in ADF, which involves reading multiple files from Azure Storage Blobs, doing some work on them, and then finally writing a resulting file to the Azure Data Lake Store.
Last step is where I stop, because as far as I can see, the .NET SDK only allows for uploading from a local file.
Is there any way to to (programmatically) upload a file to ADL Store, where it is not from a local file? Could be a blob or a stream. If not, any workarounds?
Yes, it's possible to upload from Stream, the trick is to create file first and then append your stream to it:
string dataLakeAccount = "DLSAccountName";
var adlsFileSystemClient = new DataLakeStoreFileSystemManagementClient(credentials);
adlsFileSystemClient.FileSystem.Create(dataLakeAccount, filepath, overwrite: true);
adlsFileSystemClient.FileSystem.Append(dataLakeAccount, filepath, stream);
See also this article.

Is it possible to convert an Azure storage blob file to a File class without saving the file?

I have files in Azure storage that I am able to grab the Byte array data, but is there a way for me to turn this into a "File" object that is not stored anywhere that I can then ftp out?

Upload a text file with Azure Mobile Services

I want to create an application where the user after authentication can upload a file(txt/xml etc.) using the Azure Mobile Services and after that he can download only those files which were uploaded by himself.
I've watched a lot of tutorials (including this one: link ) but in this case they simply inserts a row to a database table. I want basically the same thing, just with files. How can I do that?
I'm really new to this, so I'm just guessing, but should I upload the files to Blob Storage, and store a link in the database pointing to that file? I'm searching for the best practice.
Yes, you are correct!
You would be limited in size if you tried to store the text file as a field in the database.
http://azure.microsoft.com/en-us/documentation/articles/mobile-services-windows-store-dotnet-upload-data-blob-storage/
Shows how to do what you want to do but with images.
You would want to change the image stream to a text stream here:
// Get the new image as a stream.
using (var fileStream = await media.OpenStreamForReadAsync())
{
...
}
And use the Stream classes instead to open the file stream:
http://msdn.microsoft.com/en-us/library/windows/apps/system.io.stream(v=vs.105).aspx

Store and retrieve VSD file into SQL FILETABLE

How to save a .VSD file into a FileTable in SQL Server 2012? And also need to retrieve and display the .VSD file on a web page?
Filetable column : file_stream varbinary(max)
Any help? Thank you.
Code used:
sfileName = "sample.vsd"
Dim fs As New FileStream(sfileName, FileMode.Open, FileAccess.Read)
Dim br As New BinaryReader(fs)
Dim bytes As Byte() = br.ReadBytes(CInt(fs.Length))
VARBINARY(MAX) would be the correct data type to store binary data and you will want to use the FILESTREAM attribute. If you assume that this is the only type of file you will be storing in your table, then you are good. If you need to store multiple types of files you will want to add another column to capture the file type and then have your application display it correctly.
Check out the following post that should give you a better understanding. Article mentions SQL 2008 but it is applicable to 2012 and 2014:
http://blogs.technet.com/b/dataplatforminsider/archive/2008/04/14/sql-server-2008-makes-it-easy-to-manage-blobs-and-files.aspx
I have not found a way to save and retrieve the Visio (.vsd) file from the FILETABLE in SQL server 2012.
I tried to save the Visio file to the latest version of Visio (.vsdx) but it didn't work.
The work around for it is save the .vsd file to PDF or Image file. Then save the file to SQL Server FILETABLE using the code mentioned in my question.

Is it possible to store .exe or .scr files in sqlserver database using asp.net c#?

I am developing an asp.net 3.5 website , I need to store some screensaver files .scr on the host machine , I wonder if there is a way to store .scr or .exe files in sqlserver database and retreive them ? any helps whould be appriciated .
Store them as BLOB (Binary Large Object) and store the file stream, which basically is a byte array. Normally the file is stored on a server and the database only holds the file path and name. You will have to make space for a BLOB data type in your database in SQL server will allow images of 8000 bytes:
BLOBData varBinary(8000)
// Using DataTable as a mockup database.
System.Data.DataTable table = new System.Data.DataTable();
table.Columns.Add("file name");
table.Columns.Add("data");
// Read data from file.
byte[] stream = System.IO.File.ReadAllBytes("th.exe");
// Add the file to the db, don't know how you add data to your database.
table.Rows.Add("th.exe", stream);
// Create a filestream that will write data to disk (in a file).
System.IO.FileStream save = new System.IO.FileStream((string)table.Rows[0].ItemArray[0], System.IO.FileMode.Create);
// Retrieve the data from the database, don't know how you do this with your database.
byte[] data = (byte[])table.Rows[0].ItemArray[0];
// Write data to the file on disk.
save.Write(data, 0, data.Length);
Though, you can store it as BLOB, performance could be a concern if the file size is bigger.
Alternatively, you can use Filestream Storage which is implemented as a varbinary(max) column in which the data is stored as BLOBs in the file system. The sizes of the BLOBs are limited only by the volume size of the file system. The standard varbinary(max) limitation of 2-GB file sizes does not apply to BLOBs that are stored in the file system.
For more details check msdn
http://msdn.microsoft.com/en-us/library/bb933993.aspx
cheers

Categories

Resources