简体   繁体   中英

Saving image file into the database

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.

I would love if you first search on gooogle and than ask for the help if you find out difficult to understand anyways check the following article help you to achieve your task

C# Save and Load Image from Database

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM