here is the example to upload the file for the various file formate.
you can uplaod the file with the below paradigm, the below programme is to upload the jpg file formate.
protected void btnUpload_Click(object sender, EventArgs e)
{
string checkEmpPhoto ;
checkEmpPhoto = txtEmpid.Text + ".JPG";
if (upESDPhoto.HasFile)
{
string extension = System.IO.Path.GetExtension(upESDPhoto.FileName);
if (extension.ToUpper() == ".JPG")
{
if (checkEmpPhoto.ToString().ToUpper() == upESDPhoto.FileName.ToString().ToUpper())
{
if upload to same application folder
upESDPhoto.SaveAs(Server.MapPath("Folder Name") + "\\" + upESDPhoto.FileName);
if upload to some other server folder
upESDPhoto.SaveAs(@"\\\\Server Name or Server IP\Folder Name" + "\\" + upESDPhoto.FileName);
lblMsg.Text = upESDPhoto.FileName + " uploaded Successfully.";
}
else
{
lblMsg.Text = "Please check the Photo Name.";
}
}
else if (extension.ToUpper() != ".JPG")
{
lblMsg.Text = "Wrong File Formate.";
}
}
else
{
lblMsg.Text = "Please select File first.";
upESDPhoto.Focus();
}
}
you can uplaod the file with the below paradigm, the below programme is to upload the jpg file formate.
protected void btnUpload_Click(object sender, EventArgs e)
{
string checkEmpPhoto ;
checkEmpPhoto = txtEmpid.Text + ".JPG";
if (upESDPhoto.HasFile)
{
string extension = System.IO.Path.GetExtension(upESDPhoto.FileName);
if (extension.ToUpper() == ".JPG")
{
if (checkEmpPhoto.ToString().ToUpper() == upESDPhoto.FileName.ToString().ToUpper())
{
if upload to same application folder
upESDPhoto.SaveAs(Server.MapPath("Folder Name") + "\\" + upESDPhoto.FileName);
if upload to some other server folder
upESDPhoto.SaveAs(@"\\\\Server Name or Server IP\Folder Name" + "\\" + upESDPhoto.FileName);
lblMsg.Text = upESDPhoto.FileName + " uploaded Successfully.";
}
else
{
lblMsg.Text = "Please check the Photo Name.";
}
}
else if (extension.ToUpper() != ".JPG")
{
lblMsg.Text = "Wrong File Formate.";
}
}
else
{
lblMsg.Text = "Please select File first.";
upESDPhoto.Focus();
}
}