Bernhard Hiller wrote:
That's a very bad, really terrible, coding practice. Don't do so.
Thank a lot for the advice but I have a check I am handling it on button click for now, will change it once I get the uploading fixed.
Bernhard Hiller wrote:
Also note: how will you later be able to access those files? Do you have some database table or some other mechanism to find out which files exist and to generate the html links to them?
Following is my button click event, I hope this will help you understand the rest of the code and yes I am storing it in the database and displaying them on another page in a grid.
protected void btnAdd_Click(object sender, EventArgs e)
{
string isBest;
if (cbIsBest.Checked)
{
isBest = "Yes";
}
else
{
isBest = "No";
}
string picPath = UploadPicture(); // uploads picture using file upload control and stores it in ImgNewsletter folder
string newsletterPath = UploadNewsletter(); // uploads newsletter using file upload control and stores it in Newsletter folder
if (picPath == "")
{
divError.InnerText = "Please select an image for the newsletter.";
}
if (newsletterPath == "")
{ divError.InnerText = "Please provide the e-copy of newsletter."; }
else {
try
{
string uploadedBy = Session\["Email"\].ToString();
if (dl.insertNewsletter(txtTitle.Text, ddlMonth.SelectedItem.ToString(), areaSummery.Text, picPath, newsletterPath, ddlCohort.SelectedItem.ToString(), isBest, uploadedBy)>0)
{
divSuccess.InnerText = "Thanks! Mahara Insight has been uploaded successfully.";
divSuccess.Visible = true;
}
else
{
divSuccess .InnerText = "Sorry for inconvenience. Some error has occured. Please try later.";
divSuccess.Visible = true;
}
}
catch (Exception ex)
{
divError.InnerText = "Sorry for inconvenience. Some error has occured. Please try later.";
}
}
}
Regar