to save the filepath to the database

Posted by Shreesh under ASP.NET on 10/21/2011 | Points: 10 | Views : 1188 | Status : [Member] | Replies : 1
hello,
the code below is the code i have used in FileUpload control,it saves the file onto the database directly. i want to save the filepath to the database and not the entire file.


protected void Button1_Click(object sender, EventArgs e)
{
con.Open();
cmd = new SqlCommand("db_vid",con);
cmd.Connection = con;
cmd.CommandType = CommandType.StoredProcedure;
s = FileUpload1.FileName ;
cmd.Parameters.AddWithValue("@video",s);
cmd.ExecuteNonQuery();
con.Close();



if (FileUpload1.PostedFile.FileName != null && FileUpload1.PostedFile.ContentLength > 0)
{


string filename = Path.GetFileName(FileUpload1.PostedFile.FileName);
string _fpath = Server.MapPath("~/folder") + FileUpload1.FileName;
FileUpload1.SaveAs(_fpath);
Label2.Visible = true;
Label3.Visible = false;

}
}





Responses

Posted by: SheoNarayan on: 10/21/2011 [Administrator] HonoraryPlatinum | Points: 25

Up
0
Down
Based on the above code snippet, it is not saving the entire file but it is saving the file name only to the database. FileUpload1.FileName gives just the name of the file selected by the user.

Would suggest you to read following post

http://www.dotnetfunda.com/tutorials/controls/fileupload.aspx
http://www.dotnetfunda.com/articles/article981-multiple-files-upload-in-aspnet-and-aspnet-with-jquery.aspx

Thanks

Regards,
Sheo Narayan
http://www.dotnetfunda.com

Shreesh, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response