This is a migrated thread and some comments may be shown as answers.

Saving a word doc/docx file to DB.

3 Answers 362 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Deepika
Top achievements
Rank 1
Deepika asked on 17 Feb 2012, 06:37 AM
Hello,
I want to save a file to database. I have a grid template column, in that I have RadUpload control. From this I will have to get the input file from user. I need to save this file in the database. I do not want to use the query in the aspx page. I want to save this file to DB in

rdgAddUpdFile_InsertCommand

method. What should be the DB column Type for this? Should this be text or Varchar?
Also, how to get this data saved again for reconstructing this file for download?
Thanks and Regards,
Deepika Karanth

3 Answers, 1 is accepted

Sort by
0
Richard
Top achievements
Rank 1
answered on 20 Feb 2012, 10:57 PM
Deepika:

You have not mentioned what type of database that you are using to store the uploaded files. I will assume, here, that you're using SQL Server 2008.

The method that you use to store your files depends on their average size and whether you want to be able to perform a full-text search on them. You may want to consider using the FileStream Data Type for large documents typically over 1 MB. See this article for insights: FileStream Data Type : SQL Server 2008.

If your typical document is smaller, you'd be better to store them as varbinary(max) BLOBs.

I found this thread extremely informative as to the pros and cons of different options: Best Way to Store Documents In SQL Server.

Hope this helps!
0
RvdGrint
Top achievements
Rank 1
answered on 21 Feb 2012, 09:10 AM
Deepika,

I'm using RadUpload for storing documents etc. in a SQL database:
if (ruFiles.UploadedFiles.Count > 0)
{
  foreach (UploadedFile validFile in ruFiles.UploadedFiles)
  {
    byte[] bytes = new byte[validFile.InputStream.Length];
    validFile.InputStream.Read(bytes, 0, Convert.ToInt32(validFile.InputStream.Length));
 
    FIN_EntryFileDAL.FIN_EntryFile _Object = new FIN_EntryFileDAL.FIN_EntryFile();
 
    _Object.FileName = validFile.GetName();
    _Object.FullFileName = validFile.FileName;
    _Object.Subject = tbUploadSubject.Text;
    _Object.FileLength = validFile.ContentLength;
    _Object.FileMimeType = validFile.ContentType;
    _Object.FileData = bytes;
 
   //Function which calls the stored procedure for inserting the record
    new FIN_EntryFileDAL().Insert(_Object);
  }
}
else if (ruFiles.InvalidFiles.Count > 0)
{
  foreach (UploadedFile invalidFile in ruFiles.InvalidFiles)
  {
     if (invalidFile.ContentLength > ruFiles.MaxFileSize)
      lblWarning.Text = "File to large".GetTranslation() + " (" + invalidFile.FileName + ")";
  }
 
  bOk = false;
}

Regards,
  Jos Meerkerk



 

0
Arron
Top achievements
Rank 1
answered on 25 Apr 2014, 04:12 AM
Hi, Deepika.
As for me, I am using another Word document control instead of RadUpload control. And I have never met with such a problem when I save a file to database. Have you ever found your way out? How about changing another Word SDK to have a try? I hope you success. Good luck.



Best regards,
Arron
Tags
Grid
Asked by
Deepika
Top achievements
Rank 1
Answers by
Richard
Top achievements
Rank 1
RvdGrint
Top achievements
Rank 1
Arron
Top achievements
Rank 1
Share this question
or