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 .
-
are you sure you want to store these images into database? because it consume a lot of space ?rahularyansharma– rahularyansharma2011-07-04 11:02:42 +00:00Commented Jul 4, 2011 at 11:02
-
1codeproject.com/KB/database/ImageSaveInDataBase.aspxrahularyansharma– rahularyansharma2011-07-04 11:04:27 +00:00Commented Jul 4, 2011 at 11:04
-
shabdar.org/sql-server/105-store-save-images-in-sql-server.htmlrahularyansharma– rahularyansharma2011-07-04 11:04:44 +00:00Commented Jul 4, 2011 at 11:04
-
possible duplicate of [C# : Saving an Image into DB ](stackoverflow.com/questions/5806159/c-saving-an-image-into-db)marc_s– marc_s2011-07-04 11:08:13 +00:00Commented Jul 4, 2011 at 11:08
-
i have already seen that.but i didnt get a good answer theresaurabh goyal– saurabh goyal2011-07-04 11:12:57 +00:00Commented Jul 4, 2011 at 11:12
Add a comment
|
1 Answer
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