0

how can i save the file using c# into the SQL server dataqbase after user has selected the file location using fileupload control in asp.net .

Muhammad Akhtar
  • 51,913
  • 37
  • 138
  • 191
saurabh goyal
  • 1,754
  • 8
  • 35
  • 45

1 Answers1

0

You might try something like this:

if (this.fileUploader.PostedFile == null ||
    this.fileUploader.PostedFile.ContentLength < 1)
{
   this.LabelError.Text = this.GetGlobalResourceObject("Messages", "NoFileToUpload")
                              .ToString();
   return;
}

MyTableWithImageField i = new MyTableWithImageField();

i.ImageData = this.fileUploader.FileBytes;

command.CommandText = @"InsertMyTableWithImageField";
command.CommandType = CommandType.StoredProcedure;

command.Parameters.AddWithValue("@ImageData", i.ImageData);

You may also want to check this from MSDN: Uploading Files in ASP.NET 2.0

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574