파일을 업로드하고 이름을 아래로 변경하려고합니다. 파일 확장자를 가져와야합니다. 아래의 코드는 "Path"밑에 밑줄이 있는데, using 문이 없습니까? 또는 내가하고있는 것에 대한 올바른 구문은 무엇입니까?FileUpload는 파일 확장자를 가져옵니다.
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.";
}
대단히 감사합니다. –