Tôi đang cố tải tệp lên và thay đổi tên của tệp bên dưới. Tôi cần phải nhận được phần mở rộng tập tin. Đoạn mã dưới đây có gạch chân dưới "Đường dẫn", tôi có thiếu câu lệnh sử dụng không? Hoặc cú pháp chính xác cho những gì tôi đang làm là gì?FileUpload tải tệp mở rộng
if (FileUpload1.HasFile)
try
{
var FileExtension = Path.GetExtension(FileUpload1.PostedFile.FileName).Substring(1);
var newName = DateTime.Now.ToLongDateString();
//Map path to folder
string realpath = Server.MapPath("Pictures\\") + Guid.NewGuid() + FileExtension;
FileUpload1.SaveAs(realpath);
Label1.Text = "File name: " +
FileUpload1.PostedFile.FileName + "<br>" +
FileUpload1.PostedFile.ContentLength + " kb<br>" +
"Content type: " +
FileUpload1.PostedFile.ContentType;
}
catch (Exception ex)
{
//Handle the error
throw ex;
}
else
{
Label1.Text = "You have not specified a file.";
}
Cảm ơn rất nhiều. –