.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

Binary content of any file..

Posted By:      Posted Date: October 02, 2010    Points: 0   Category :ASP.Net

help me--

1. I have a file upload tool to get any file okay..

2. I want to get binary format of any file that i browse through upload tool and

3. I want to save it in another file say any text file or database or any custom file type


4. Now that i've binary format of any file say a image file, how can i recreate the file

   from it's binary content...

all i need is....FIle to Binary and then Binary to Original File. 

View Complete Post

More Related Resource Links

Create excel file from Binary data on SqlServer



My requirement is that i upload an excel file then i need to validate that data.


1. Uploading file using using upload control saving binary in SqlServer

2. Then i am creating file from binary data  on Sql Server using below command and then using OPENROWSET to dump data to Sql table

3. Then reading Sql Table row wise and validating data.


Alter Procedure spUploadExcelFile
  @PKID int,
  @BatchID int


	Declare @VarBin varbinary(max)
	Declare @FileName varchar(100)
	DECLARE @sql nvarchar(MAX)
                DECLARE @errMsg nvarchar(MAX)
	DECLARE @ObjectReturn INT
	DECLARE @ErrorSource VARCHAR(255)
	DECLARE @ErrorDesc VARCHAR(255)
	DECLARE @ObjectToken INT

	Select @VarBin  = Content , @FileName = [FileName] from MultilangBinaryData Where PKID = @PKID
	SET @FileName = 'C:\'  + @FileName
	EXEC sp_OACreate 'ADODB.Stream' @ObjectToken OUTPUT
	EXEC sp_OASetProperty @ObjectToken, 'Type', 1
	EXEC sp_OAMethod @ObjectToken, 'Open'
	EXEC sp_OAMethod @ObjectToken, 'Write', NULL, @VarBin
	EXEC sp_OAMethod @ObjectToken, 'SaveToFile', NULL, @FileName, 2
	EXEC sp_OAMethod @ObjectToken, 'Close'
	EXEC sp_OADestroy @ObjectToken  
	SET @sql = 'INSERT INTO dbo.UserBulkData SELECT 0,NULL,'+ @BatchI

Read an XML file, setting uname/pw, Accept, Content-Type

Hi; To read some REST XML data we need to set the username, password, and tell it for the http request Accept: application/xml Content-Type: application/xml Is there a sample anywhere showing how to do this? thanks - daveVery funny video - Reporting as a Metaphor

How to load binary file asynchronously

I need to be able to download file from local disk or UNC path asynchronously. I've tried to use FileStream, but not sure what is the best way to read file by small chunks and combine them together then. Btw, does it make sense to download file by small chunks? Here is what I tried: byte[] _content; void Start(){ FileInfo fi = new FileInfo(path); if(fi.Exists) { FileStream fs = new FileStream(path, FileMode.Open); var stateObject = new State(fs, fi.Length); fs.BeginRead(stateObject.Buffer, 0, (int)stateObject.BufferSize, new AsyncCallback(EndReadCallback), stateObject); } } ... public void EndReadCallback(IAsyncResult asyncResult) { State state = (State)asyncResult.AsyncState; int readCount = state.FStream.EndRead(asyncResult); //store bytes inside class instance this._content = state.Buffer; //close stream state.FStream.Close(); if(FileLoaded != null) { FileLoaded.Invoke(_content); } } Thanks in advance, Paul.

How to add link to a css file in content page?

How to add link to a css file in content page? There is no Head tag.

Linking JS file to ASPX page or content page

Hi, I moved my JS functions into an external file "JScript.js", because I'm now using a master page and a content page.But it doesn't work any more, and I can't find why.I tried simply to link a js file to an ASPX file, by adding to the script manager the path of my script, but it doesn't work.Here is my js file (we don't need any special things in it do we?) var step1 = false; function pageLoad() { var accCtrl = $find('AccordionCtrl_AccordionExtender'); accCtrl.add_selectedIndexChanged(onAccordionPaneChanged); } function hideAccordionPane(paneNo) { ... } function changeSelected(idx) { ... } function onAccordionPaneChanged(sender, eventArgs) { ... } function check() { ... }And here is my ASP code: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0

Read Binary Data which is nothing but a Zip file and unzip through SSIS 2005 SP2

Hi ALL, I need some help in developing a task. I have a source database which is Oracle and it has a ZIP file stored inside the database in Binary format. When I move this data into the sql server 2005 database I get the data as binary data. Now the task begins with SSIS, I need to read the binary data which gives us a zip file and then unzip this zip file and read the XML data which is present inside the Zip file. I beleive some one might have already developed this task can you share the solution with us. Note: As this has to be moved into production I dont have permission to use third party tools like Cozy roc or install winrar.exe and simpy calling this exe from the execute process task in SSIS.  Raju

Inserting a Binary file in SQL Server 2000

Hi all, I want to store a native binary file into the DB having the column datatype as 'image', in SQL Server 2000, through SQL Query. I have found the solution for the case of 2005, thet is using the OPENROWSET and BULK. Can you please help me out in constructing the SQL or TSQL Query for performing that operation? Thanks a Bunch in Advance :)

Insertion of a Binary File in SQL Server 2000

Hi all, I want to insert a binary file into the SQL Server 2000. The type of the column reserved for the file is of 'image' datatype. I have found the solution for the SQL Server 2005 and later, using the open rowset. Can you please give me a SQL/T-SQL Query for the operation? Thanks a bunch in advance :)

WCF MTOM Client calling Java Webservice - Issues with File attachment Content ID encoded in SOAP mes

Hello,I'm having difficulty calling a MTOM enabled Java based web service that accepts an file as input..NET appeats to be generating a SOAP message where the reference to the binary part of the message is an encoded url.For Example:  <inc:Include href="cid:http%3A%2F%2Ftempuri.org%2F1%2F634000265217257868" xmlns:inc="http://www.w3.org/2004/08/xop/include"/>In fact, the Content ID defined in the SOAP message, looks nothing like the actual Content ID of the actual message part.Content-ID: <http://tempuri.org/1/634000265217257868=2787915398744@soapui.org>The service is invoked and executed on the java webserver...but the data element appears to be null.I do not believe the java web server understands the reference in the SOAP message because it is encoded....Or...perhaps it's because the Content-ID attribute has extract stuff on it.I'm working with a custom MTOM encoder in WCF....is there a way to generate your own Content ID or tell .NET not to encode the url?My frustration with .NET has reached an all new level with this project...Any help would be greatly appreciated.Here the SOAP message that is being generated:<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope" xmlns:ns="http://docs.oasis-open.org/ns/cmis/messaging/200901" xmlns:ns1="http://docs.oasis-open.org/ns/cmis/core/200901&q

How to send binary data ( ogg audio file) using a web service?


Hi folks, I would appreciate any help or guidance on this topic:

How can I receive binary data (specifically an ogg audio file) using a WCF4 service?

The general idea is to define and host a WCF service inside IIS that returns an audio file (ogg file)

I have read some info related with using ByteStreamMessageEncodingBindingElement class to achieve this, also I read some topic related on using MTOM to attach a binary file. It seems that it can be several ways or approaches to achieve this.

So any guidance on the themes and/or examples for the better way to solve this point would be very appreciated.

Thanks in advance.



Reading Binary file


Hi All, 

 I am using BinaryReader class to read binary file.But I am facing problem while reading number of  bytes from it.

I have written code to read only 2 bytes from it,it works well on my machine and read only 2 bytes,but when I deployed that code on server machine it read 4 bytes from file.Whats wrong in the code?Is it due to processor i.e.. 32 bit processor/64 bit processor I am using?

Please provide solution or any link for it ASAP..

Thanks in advance




Reading strings from a binary file


I am tasked with reading various files that were saved to disk by a Visual Basic 4 application.

I've started with the easiest of the files, which contains one or more strings, each 128 bytes in length.

And so I wrote the following code to put these strings in a list:


Console.WriteLine("========== START ==========");

var list = new List<string>();

var fileStream = new FileStream("(Filename)", FileMode.Open);
var bytes = new byte[128];
while (true) {
 if (fileStream.Read(bytes, 0, bytes.Length) == 0) break;

foreach (var s in list) Console.WriteLine(s);


Console.WriteLine("========== END ==========")

How to change the content of an html file using an aspx file?


Hi everyone,

I would really like to have a little help, it should be easy but i can't find the answer

and it's been a while since iv'e done something with asp.net..

what i have now is a regular html pages website.

in some of the pages i have galleries,

I would like to make an aspx page to manage the content of the galleries or any other set-in advance content.

It's kind of a CMS, but it's not, since i would not be using a database.

what i want is just to get the admin's content from the aspx page

and send it to overwrite the images or the content of the DIVS in the html page.

at the final outcome, i will only want to have html files and one aspx file for the admin's editing use.

what is the most simple way to do that without using CMS? 

Thanks a bunch!


Save text box content as a text file in sharepoint 2010 document library


I am a sharepoint developer and currently I am trying to save content of a text box from client side in document library in share point 2010. I have created a sandbox solution for this. I explored the SP2010 client side object model for ECMA script, however I was not able to crack the problem.

I have created the byte array from the text box content and now I want to save it as a text file in the document library using ECMA script.

Kindly suggest how can I achieve that.

How to file content type in C#?


Hi Friends,

Please help know how to get file content type in C#.net.

For example, I create one asp.net project and hosted in server.  So, now I can upload any time of file.

For example:- User uploaded demo.txt file. It done successfully!

Now user can view that file for example http://ip addres[]/demowebsite/uploads/demo.txt

So, using that URL user can access that .txt file.

Now problem is, if user uploaded .aspx file or .ashx file or any other .net related file.

he can access that file using URL

For example user is uploaded a crack.aspx file with some virus program.

So, now he can execute  his code by browsing http://ip addres[]/demowebsite/uploads/crack.aspx .


I want to handle this error. if he uploaded any text content type file, I need to change those file extensions to crack.aspx.txt or crack.php.txt or crack.jsp.txt or demo.xml.txt.  Because those are content type is Text.

For this we can use this code below code to find content type

private string MimeType (string Filename)
string mime = "application/octetst ream ";
string ext = System.IO.Path.GetExtension(Filename).ToLower();
Microsoft.Win32.RegistryKey rk = Microsoft.Win32.Registry.ClassesRoot.Op

Ajax - Send Binary File to Server


Hi Guys,

Am new to Ajax coding.

Is it possible to send a binary file file from client to server using ajax???

am using ActiveXObject("Scripting.FileSystemObject") to get a binary file from client. I need to send the binary data to server.


Converting a binary file to byte array


Hi Everyone-

I'm retrieving a binary file from the database, a .pdf file that I would like to let the user open and view.  From what I can tell, there are two steps to do this: 

1. Convert binary file to byte array  

2. Convert byte array to file content 

Here's what I've got so far:

 Dim c1 = (From c In dc.Documents _
                     Where c.userID = userGuid _
                     Select New With {c.downloadName, _
                                     c.docData, _
                                     c.type, _

             Dim bArray As Byte() = CType(c1.docData("binary"), Byte())
            If bArray.Length > 0 Then
                Dim fs As System.IO.FileStream = New System.IO.FileStream("d:\xx.pdf", IO.FileMode.Create)
                fs.Write(bArray, 0, bArray.Length)
            End If

This isn't working and I'm having a heck of a time trying to find a solution.  I'm getting a blue squiggly under c1.docData in the Dim bArray line. 

What am I doing wrong?

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend