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 .

5

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.