How to retrieve file extension of uploaded file?
i have uploaded the docx, pdf and jpg file using fileupload.i designed a update form.
Now i wanted to update the new file with the existing file.how to achieve it?how to retrieve the selected files?
The below is my insertion Part:
//Insertion
if (fu_press.HasFile)
{
string ext = System.IO.Path.GetExtension(fu_press.FileName);
press = userId + "press" + ext;
fileLocation1 = Server.MapPath("images/Media/press_release/" + press);
fu_press.SaveAs(fileLocation1);
fileTxt = "1";
}
else
{
press = txtpress.Text;
}
if (fu_browsher.HasFile)
{
string ext = System.IO.Path.GetExtension(fu_browsher.FileName);
browname = userId + "broshure" + ext;
fileLocation2 = Server.MapPath("images/Media/Brouchure/" + browname);
fu_browsher.SaveAs(fileLocation2);
}
if (fu_pimg1.HasFile)
{
string ext = System.IO.Path.GetExtension(fu_pimg1.FileName);
pimg1name = userId + "prod1" + ext;
fileLocation3 = Server.MapPath("images/Media/products/" + pimg1name);
fu_pimg1.SaveAs(fileLocation3);
}
.....
...
string connectStr = ConfigurationManager.ConnectionStrings["ExpoExhibitorConnectionString"].ToString();
connect = new MySqlConnection(connectStr);
string queryStr = "insert into exb_mediainfo(title,press_release,product_imgs1,product_imgs2,product_imgs3,browsher,user_id,date,press_filetype,logo) values(?title,?press,?prod1,?prod2,?prod3,?browsher,?uid,?date,?filetype,?logo)";
connect.Open();
MySqlTransaction transaction = connect.BeginTransaction();
MySqlCommand command1 = new MySqlCommand(queryStr, connect, transaction);
command1.Parameters.AddWithValue("?title", txtitle.Text);
command1.Parameters.AddWithValue("?press", press);
command1.Parameters.AddWithValue("?prod1", pimg1name);
command1.Parameters.AddWithValue("?prod2", img2);
command1.Parameters.AddWithValue("?prod3", img3);
command1.Parameters.AddWithValue("?browsher", browname);
command1.Parameters.AddWithValue("?uid", userId);
command1.Parameters.AddWithValue("?date", todaydate);
command1.Parameters.AddWithValue("?filetype", fileTxt);
command1.Parameters.AddWithValue("?logo", logo);
command1.ExecuteNonQuery();
...
...
}
I inserted the data into the table Now i wanted to retrieve the inserted part into update form.i wanted to retrieve the selected file(fileupload).The below is the code for update:
///update:i am retrieving the values from the database
if (dt.Rows.Count > 0)
{
txtitle.Text= dt.Rows[0]["title"].ToString();
string content;
string contentb;
string contentp1;
string contentp2;
string contentp3;
string contentlogo;
string queryStr = "";
if (dt.Rows[0]["press_filetype"].ToString() == "0")
{
txtpress.Text= dt.Rows[0]["press_release"].ToString();
}
else
{
content = "http://expocrm.expogroup.info/images/Media/press_release/" + dt.Rows[0]["press_release"].ToString();
}
contentb = "http://expocrm.expogroup.info/images/Media/Brouchure/" + dt.Rows[0]["browsher"].ToString();
contentp1= "http://expocrm.expogroup.info/images/Media/products/" + dt.Rows[0]["product_imgs1"].ToString();
if (dt.Rows[0]["product_imgs2"].ToString() != "N/A")
{
contentp2 = "http://expocrm.expogroup.info/images/Media/products/" + dt.Rows[0]["product_imgs2"].ToString();
}
else
{
contentp2 = dt.Rows[0]["product_imgs2"].ToString();
}
if (dt.Rows[0]["product_imgs3"].ToString() != "N/A")
{
contentp3 = "http://expocrm.expogroup.info/images/Media/products/" + dt.Rows[0]["product_imgs3"].ToString();
}
else
{
contentp3 = dt.Rows[0]["product_imgs3"].ToString();
}
if (dt.Rows[0]["logo"].ToString() != "")
{
contentlogo = "http://expocrm.expogroup.info/images/Media/logos/" + dt.Rows[0]["logo"].ToString();
}
else
{
contentlogo = "N/A";
}
...
...
...
}
}
catch (Exception ex) { }
finally
{
if (connect.State == ConnectionState.Open)
{
connect.Close();
}
}
Any help will be highly appreciated.
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
msdn.microsoft.com/en-us/library/…
– GrandMasterFlush
6 hours ago