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 .
Asked
Active
Viewed 2,664 times
0
-
are you sure you want to store these images into database? because it consume a lot of space ? – rahularyansharma Jul 04 '11 at 11:02
-
1http://www.codeproject.com/KB/database/ImageSaveInDataBase.aspx – rahularyansharma Jul 04 '11 at 11:04
-
http://www.shabdar.org/sql-server/105-store-save-images-in-sql-server.html – rahularyansharma Jul 04 '11 at 11:04
-
possible duplicate of [C# : Saving an Image into DB ](http://stackoverflow.com/questions/5806159/c-saving-an-image-into-db) – marc_s Jul 04 '11 at 11:08
-
i have already seen that.but i didnt get a good answer there – saurabh goyal Jul 04 '11 at 11:12
1 Answers
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

Ventsy Popov
- 5
- 2