Click here to Skip to main content
15,889,842 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
here, I have downloading my document from share point document library.
when i view my document it is in binary format. how to convert to normal format.
here i have attached my code:


C#
byte[] binfile = item.File.OpenBinary();
               FileStream fstream = new FileStream(@"E:\Oliver\" + item.File.Name, FileMode.Create, FileAccess.ReadWrite);
               //fstream.Write(binfile, 0, binfile.Length);
               if (Response.IsClientConnected)
               {

                   int length = fstream.Read(binfile, 0, binfile.Length);
                   Response.OutputStream.Write(binfile, 0, binfile.Length);
                   Response.Flush();
               }

               fstream.Close();
Posted
Comments
_Amy 9-Aug-12 9:09am    
What you mean? Binary format & normal format? It's Confusing..

1 solution

I think You need to display the binary array in normal file format.

C#
private void ShowDocument(string fileName, byte[] fileContent)
        {
            //Split the string by character . to get file extension type
            string[] stringParts = fileName.Split(new char[] { '.' });
            string strType = stringParts[1];
            Response.Clear();
            Response.ClearContent();
            Response.ClearHeaders();
            Response.AddHeader("content-disposition", "attachment; filename=" + fileName);
            //Set the content type as file extension type
            Response.ContentType = strType;
            //Write the file content
            this.Response.BinaryWrite(fileContent);
            this.Response.End();
        }


Check my article.

http://www.c-sharpcorner.com/UploadFile/1a81c5/convert-file-to-byte-array-and-byte-array-to-files/[^]
 
Share this answer
 
v2
Comments
fjdiewornncalwe 9-Aug-12 11:16am    
Santosh, you should repost your article on CP as well.
Santhosh Kumar Jayaraman 9-Aug-12 21:42pm    
Ya will do that soon

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900