Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i am making small web application, i want to convert doc file into html file and save in database and retrieve from database and show on web page when page load , one thing is very important i want to save length of file not path , beaus it is security reason , kindly guide me , it is very urgent .

my code is given below

C#
public void ProcessRequest(HttpContext context)
      {
          //storing the querystring value that comes from Defaul.aspx page

          string displayimgid=context.Request.QueryString["id_Image"].ToString();
          cls.connection();
          //retriving the images on the basis of id of uploaded
          //images,by using the querysting valaues which comes from Defaut.aspx page
          cls.query="select Image from ImageToDB where id="+displayimgid;
          SqlCommand com=new SqlCommand(cls.query,cls.con);
          SqlDataReader dr=com.ExecuteReader();
          dr.Read();
          context.Response.BinaryWrite((Byte[])dr[0]);
          context.Response.End();


      }
Posted
Updated 29-Dec-14 9:02am
v4
Comments
Rene Bustos 29-Dec-14 13:15pm    
Hi Tahir Mahmood

Well, the module as you describe is a little bit unsecure, not for third persons...i mean, for your own data integrity, if your data base crash, all yours Doc (saved on Database) will lose it.

its strongly recomended to keep the file in Disk, and when you need to show it...just linked it to the client.
Sergey Alexandrovich Kryukov 29-Dec-14 15:04pm    
It might be a good advice, but your idea on "security" it totally irrelevant. The "crash" of database is not more likely than "crash" of the documents on disk.
I basically answered the question; please see.
—SA
Rene Bustos 29-Dec-14 16:54pm    
Its a good advice. about your replay. all the responses that help here, is ok.
Best Regards.
Tahir Mahmood From karachi 29-Dec-14 23:32pm    
basically we are working on online examination , we were doing same task as you are saying when start exam we linked the file , after completing we remove the link ,but reason is that our data could be copy by third party ,so that's why we want that we save html file in binary format and when start exam student login and start their papers after completing exam we truncate all data from database so we are facing how to retrieve html file from database and show on web page when student start paper.
Rene Bustos 30-Dec-14 9:23am    
ohhh i understand Tahir. let me prepare a solution ..
best regards

Newer XML-based Word document format is public, but is not a part of W3 standards, so you have to consider it foreign to the Web, so you only can deal with it on the server side, "converting" from/to HTML, as you probably correctly understand.

The best way to deal with Word document is using Open XML SDK. Please see my past answers referenced in this one:
How to add microsoft excel 15.0 object library from Add Reference in MS Visual Studio 2010[^].

See also Microsoft explanations on why Office interop is not recommended in server settings:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;q257757#kb2[^],
http://support.microsoft.com/kb/257757/en-us[^].

—SA
 
Share this answer
 
Hi Tahir

Well , i gonna try to explain about how to save a odc file to a database


SAVING A FILE ON DATABASE:

First one , you must convert a Stream or File in a Compatible Data Type in SQl,
for this, there's a lot of ways to get this Byte Array. here is the function that i use to do this:

VB
oDB.spExecNonQuery("spSaveFileToDataBase",New SqlParameter("@File", GetStreamAsByteArray(OpenFileDialog1.OpenFile)))

Private Function GetStreamAsByteArray(ByVal stream As System.IO.Stream) As Byte()
       Dim streamLength As Integer = Convert.ToInt32(stream.Length)
       Dim fileData As Byte() = New Byte(streamLength) {}

       ' Read the file into a byte array
       stream.Read(fileData, 0, streamLength)
       stream.Close()
       Return fileData
   End Function


the function shown above return a Byte Array and this can be saved in a Binary Field in SQL Server


for this you can create a little module for select the desired file to saved. in HTML you can use a Browser object.

GET THE FILE
Well the way that i get the File or some object saved on My Data Base is with this code:

VB
m_Paginas = oDb.spExecDataSet("spGetFile", _
                                          New SqlParameter("@Prefijo", Prefijo), _
                                          New SqlParameter("@Folio", Folio))


then, when i get the DataSet with the File (still in binary)
i convert it in File again:

VB
Dim Page As DataRow = m_Paginas.Tables(0).Rows(0)
        Dim AByte() As Byte = Page.Item("File")
        Dim MS As New MemoryStream(AByte)


Right now, we have a meorystream and we can convert in a desired format.

If you need more help or information, please....tell us.
Best regards.
 
Share this answer
 

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