How to retrieve file extension of uploaded file?

The name of the picture


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.





msdn.microsoft.com/en-us/library/…
– GrandMasterFlush
6 hours ago





Possible duplicate of How to find the extension of a file?
– VDWWD
6 hours ago





Which part of minimal example as per site rules does include you dumping the whole shebang on us?
– TomTom
5 hours ago





@TomTom...In short,how to retrieve the value for fileupload? Like for textbox,for retrieving,we use txtitle.Text= dt.Rows[0]["title"].ToString(); How to use the same for fileupload?
– chetan kambli
5 hours ago









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.

Popular posts from this blog

Keycloak server returning user_not_found error when user is already imported with LDAP

PHP parse/syntax errors; and how to solve them?

How to scale/resize CVPixelBufferRef in objective C, iOS