i inserted the data into the exb_mediainfo table.As you can see,i am inserting textbox and fileuploads(.docx,.pdf.,.jpeg).
https://ibb.co/gLOZ3o
how to retrieve the fileuploads in update form?
say,i uploaded the file for Article(.docx file),Product brochure(.pdf file) and Product image(.jpg file).
So when user will try to update it,those selected file will be there in fileuploads.How to achieve it?
protected void buttSubmit_Click(object sender, EventArgs e)
{
if (valid() && Page.IsValid)
{
MySqlConnection connect = null;
try
{
HttpCookie _userInfoCookies = new HttpCookie("UserInfo");
int userId = 0;
if (_userInfoCookies != null)
{
userId = Convert.ToInt32(Request.Cookies["UserInfo"].Values["session_log_id1"]);
}
string query = "select log.company,event.event_name FROM exb_login log INNER JOIN crm_event event ON log.event_id=event.event_id WHERE user_id=" + userId + " ";
classCrm classResults = new classCrm();
DataTable dtCompany = classResults.GetDataTable(query);
string company = dtCompany.Rows[0]["company"].ToString();
string comp = company.Substring(0, 3);
string eventName = dtCompany.Rows[0]["event_name"].ToString();
string fileTxt = "0";
string todaydate = DateTime.Today.ToString("yyyy-MM-dd");
string img2 = "N/A", img3 = "N/A", press, fileLocation1, fileLocation2, fileLocation3, fileLocation4, fileLocation5, fileLocation6,logo="", browname = "", pimg1name = "", mediainfo = "";
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);
}
if (fu_pimg2.HasFile && chk_img1.Checked == true)
{
string ext = System.IO.Path.GetExtension(fu_pimg2.FileName);
img2 = userId + "prod2" + ext;
fileLocation4 = Server.MapPath("images/Media/products/" + img2);
fu_pimg2.SaveAs(fileLocation4);
}
if (fu_pimg3.HasFile && chk_img2.Checked == true)
{
string ext = System.IO.Path.GetExtension(fu_pimg3.FileName);
img3 = userId + "prod3" + ext;
fileLocation5 = Server.MapPath("images/Media/products/" + img3);
fu_pimg3.SaveAs(fileLocation5);
}
if (fu_logo.HasFile)
{
string ext = System.IO.Path.GetExtension(fu_logo.FileName);
logo = userId + "logo" + ext;
fileLocation6 = Server.MapPath("images/Media/logos/" + logo);
fu_logo.SaveAs(fileLocation6);
}
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();
transaction.Commit();
connect.Close();
mediainfo = mediainfo + "<br><br>Article Title :" + txtitle.Text.Trim() + "<br>";
if (fu_press.HasFile)
{
mediainfo = mediainfo + "<br> Article/Press Release : " + "http://expocrm.expogroup.info/images/Media/press_release/" + press;
}
else
{
mediainfo = mediainfo + "<br>Article/Press Release : " + press;
}
mediainfo = mediainfo + "<br><br> Brouchure : " + "http://expocrm.expogroup.info/images/Media/Brouchure/" + browname;
mediainfo = mediainfo + "<br><br> Product image : " + "http://expocrm.expogroup.info/images/Media/products/" + pimg1name;
if (img2 != "N/A")
{
mediainfo = mediainfo + "<br><br> Product image 2: " + "http://expocrm.expogroup.info/images/Media/products/" + img2;
}
if (img3 != "N/A")
{
mediainfo = mediainfo + "<br><br> Product image 3: " + "http://expocrm.expogroup.info/images/Media/products/" + img3;
}
if (logo != "")
{
mediainfo = mediainfo + "<br><br> Company Logo: " + "http://expocrm.expogroup.info/images/Media/logos/" + logo;
}
string companyName = company;
string ipAddress = Request.ServerVariables["REMOTE_ADDR"];
string message;
message = "Ip Address: " + ipAddress;
message = message + "<br>Exhibitor Management - Media Info Details " + "<br>Exhibition Name :" + eventName;
message = message + mediainfo;
SendMail sndMail = new SendMail();
sndMail.sendMailAndCC("expocrm@expogroup.info", "mahi@expogr.com", "expocrm@expogroup.info", message, "Media Info Details-" + eventName, "Media Info Details - " + companyName);
string script = "alert('Media info Details has been Added Successfully ...') ";
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Test", script, true);
}
catch (Exception ex)
{
}
finally
{
if (connect.State == ConnectionState.Open)
{
connect.Close();
}
txtpress.Text = "";
txtitle.Text = "";
lblimg2.Text = "";
lblpresrl.Text = "";
lblimg3.Text = "";
lblbrousize.Text = "";
GetCurrMediaInfoDetails();
}
}
}
public bool valid()
{
bool val = true;
if (fu_press.HasFile==false && txtpress.Text == "")
{
lblpresrl.Text = "Please upload the press release docx/txt file or write in the text area provided";
val = false;
}
else if (fu_press.HasFile == true && txtpress.Text != "")
{
lblpresrl.Text = "Please upload the press release docx/txt file `OR` write in the text area provided";
val = false;
}
if (chk_img1.Checked==true && fu_pimg2.HasFile == false)
{
val = false;
lblimg2.Text = "Please upload image 2";
}
else if (chk_img1.Checked==false && fu_pimg2.HasFile == true)
{
val = false;
lblimg2.Text = "Please check the checkbox to upload image 2";
}
if (chk_img2.Checked==true && fu_pimg3.HasFile == false)
{
val = false;
lblimg3.Text = "Please upload image 3";
}
else if (chk_img2.Checked == false && fu_pimg3.HasFile == true)
{
val = false;
lblimg3.Text = "Please check the checkbox to upload image 3";
}
if (fu_browsher.HasFile)
{
string ext = System.IO.Path.GetExtension(fu_browsher.FileName);
double filesize = fu_browsher.FileContent.Length;
if (filesize > 2097152)
{
val = false;
lblbrousize.Text = "size exceeds 2MB";
}
}
if (fu_logo.HasFile)
{
double filesize = fu_logo.FileContent.Length;
if (filesize > 1048576)
{
val = false;
lblogosizemsg.Text = "File size exceeds 1MB";
}
}
return val;
}
Any help will be highly appreciated.