save only path of file in SQL DB

Posted by Sanoop under ASP.NET on 12/20/2011 | Points: 10 | Views : 869 | Status : [Member] | Replies : 4
Hi friends,
I want the code for saving only the path of the file in DB while using file upload tool.




Responses

Posted by: Sksamantaray on: 12/20/2011 [Member] Silver | Points: 25

Up
0
Down
Where do you want to keep the selected file physically?
In current project directory or in a sub-directory .
If current directory : Server.MapPath("~/") or
Server.MapPath("~/subfoldername") can be used


Thanks,
Sanjay

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

Posted by: Sanoop on: 1/4/2012 [Member] Starter | Points: 25

Up
0
Down
can any one post the code for saving only path of video file in DB

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

Posted by: Avdesh on: 1/6/2012 [Member] Starter | Points: 25

Up
0
Down
#region
SqlConnection con;
SqlCommand cmd;
SqlDataAdapter da;
DataSet ds;
string a, b, c, d;
#endregion
protected void Page_Load(object sender, EventArgs e)
{
con = new SqlConnection(ConfigurationManager.ConnectionStrings["cn"].ConnectionString);
if (!IsPostBack)
{
bind();
}
}
void bind()
{
da = new SqlDataAdapter("select * from demoimg", con);
ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
string[] aa = Guid.NewGuid().ToString().Split('-');
string[] bb = FileUpload1.FileName.Split('.');
string cc = aa[0] +"."+ bb[1];
FileUpload1.PostedFile.SaveAs(Server.MapPath("saveimg\\" + cc));
cmd = new SqlCommand("insert into demoimg values(@a,@b)", con);
cmd.Parameters.AddWithValue("@a", TextBox1.Text);
cmd.Parameters.AddWithValue("@b", cc);
con.Open();
cmd.ExecuteNonQuery();
con.Close();

}
bind();
}

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

Posted by: Avdesh on: 1/6/2012 [Member] Starter | Points: 25

Up
0
Down
IT COULD BE LIKE THIS
THANKS REGARDS
(AVDESH)

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

Login to post response