title: inserting files in sql server
body: <p>greetings!</p>
  
  <p>I'm having some problems on a system that I'm giving support.
  There's a scenario where users can upload their resumé to the database (MS SQL Server 2005) and it was decided that the application should store these documents in a table with a varbinary column. I Tried many examples found on the internet but I can't figure out why the application does not store bytes from a microsoft word document (.doc). If I try to store a more recent version (.docx or xlsx) or even a .txt, the functionality works perfectly.</p>
  
  <p>I tried also store pdf files in that same column but didn't work too.
  I guess it is something with document format, i don't know</p>
  
  <p>Could you guys give some help. I'm desperate looking for one solution.</p>
  
  <p>Here's the script that I created for my table:</p>
  
  <pre><code>CREATE TABLE [dbo].[resumes](
      [id_professional] [int] NOT NULL,
  [professional_name] [varchar](50)  NULL,
  [file_type] [varchar](50) NULL,
  [data] [varbinary](max)  NULL,
  CONSTRAINT [PK_resumes] PRIMARY KEY CLUSTERED 
  (
      id_professional] ASC
  )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF,
  ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]) ON [PRIMARY]
  </code></pre>
  
  <p>And here's the code that I'm trying make it work:</p>
  
  <pre><code>foreach (string upload in Request.Files)
  {
      //create byte array of size equal to file input stream
  byte[] fileData = new byte[Request.Files[upload].InputStream.Length];
  //add file input stream into byte array
  Request.Files[upload].InputStream.Read(fileData, 0,
      Convert.ToInt32(Request.Files[upload].InputStream.Length));
  //create system.data.linq object using byte array
  System.Data.Linq.Binary binaryFile = new System.Data.Linq.Binary(fileData);
  
  Resume objResume = new Resume()
  objResume.data= binaryFile;
  
  ResumeDAO.Save(objResume);
  }
  </code></pre>
  
  <p>By the way, i 'm using linq to sql in this application.</p>