using System;
using System.IO;
using System.Linq;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Assignment : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
protected void Button2_Click(object sender, EventArgs e)
{
// Log or debug statement to check if this method is called
System.Diagnostics.Debug.WriteLine("Button clicked!");
if (FileUpload1.HasFile)
{
try
{
// Define the folder path where files will be saved
string folderPath = @"C:\MONCY\Proji\Resumes";
// Get the file name
string fileName = Path.GetFileName(FileUpload1.FileName);
// Get the file extension and convert it to lowercase
string fileExtension = Path.GetExtension(fileName).ToLower();
// Define allowed file extensions
string[] allowedExtensions = { ".pdf", ".doc", ".docx", ".txt" };
// Validate the file extension
if (!allowedExtensions.Contains(fileExtension))
{
Label5.Text = "Error: Only PDF, DOC, DOCX, and TXT files are
allowed.";
Label5.Visible = true;
return; // Exit the method if the file type is not allowed
}
// Combine path and filename
string fullPath = Path.Combine(folderPath, fileName);
// Check for duplicate files
if (File.Exists(fullPath))
{
Label5.Text = "Error: A file with this name already exists.";
Label5.Visible = true;
return; // Exit the method if the file exists
}
// Save the file
FileUpload1.SaveAs(fullPath);
// Display success message
Label5.Text = "Submitted successfully!";
Label5.Visible = true; // Make label visible
}
catch (Exception ex)
{
Label5.Text = "Error: " + ex.Message;
Label5.Visible = true; // Make label visible
}
}
else
{
Label5.Text = "Please select a file to upload.";
Label5.Visible = true; // Make label visible
}
}
}
protected void Page_PreRenderComplete(object sender, EventArgs e)
{
System.IO.DirectoryInfo di = new
System.IO.DirectoryInfo(Server.MapPath("~/resumes"));
DataList1.DataSource = di.GetFiles();
DataList1.DataBind();
}
protected void Button2_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
if (FileUpload1.FileContent.Length < 10000)
{
FileUpload1.SaveAs(Server.MapPath("~/resumes/" +
FileUpload1.FileName));
}
}