Search code examples
c#asp.netsql-serversql-server-2005varbinary

ASP.NET Store uploaded file sql server table


How do you store a file that was uploaded by an ASP.net webform into a sql server 2005 varbinary(max) field?

Here is what I have so far:

protected void btnUpload_Click(object sender, EventArgs e)
{
    for (int i = 0; i < Request.Files.Count; i++)
    {
        StoreFile(Request.Files[i]);
    }
}

private void StoreFile(HttpPostedFile file)
{
    // what do i do now?
}

A plain old ado.net example would be good. So would a linq to sql example.

Thanks


Solution

  • There's nice tutorial on how to upload a file directly into the database at 4GuysFromRolla