불만 사항 양식을 개발 중입니다. 이 양식에서는 파일을 업로드 한 다음 업로드 된 파일을 삭제하는 기능을 만들어야합니다. 서버에 파일을 업로드 할 수는 있지만 파일을 삭제하기 위해 업로드 한 파일의 링크를 서버로 가져갈 수 없습니다. 도와주세요. 여기 내 코드 :파일 업로드 제어를 사용하여 파일 업로드 및 삭제 asp.net
public string FilePath;
protected void btAdd_Click(object sender, EventArgs e)
{
if (AttachFile.HasFile)
{
try
{
string[] sizes = {"B", "KB", "MB", "GB"};
double sizeinbytes = AttachFile.FileBytes.Length;
string filename = Path.GetFileNameWithoutExtension(AttachFile.FileName);
string fileextension = Path.GetExtension(AttachFile.FileName);
int order = 0;
while (sizeinbytes >= 1024 && order + 1 < sizes.Length)
{
order++;
sizeinbytes = sizeinbytes/1024;
}
string result = String.Format("{0:0.##} {1}", sizeinbytes, sizes[order]);
string encryptionFileName = EncrytionString(10);
FilePath = "Path" + encryptionFileName.Trim() + AttachFile.FileName.Trim();
AttachFile.SaveAs(FilePath);
}
catch (Exception ex)
{
lbMessage.Visible = true;
lbMessage.Text = ex.Message;
}
}
}
protected void btDelete_Click(object sender, EventArgs e)
{
try
{
File file = new FileInfo(FilePath);
if (file.Exists)
{
File.Delete(FilePath);
}
}
catch (FileNotFoundException fe)
{
lbMessage.Text = fe.Message;
}
catch (Exception ex)
{
lbMessage.Text = ex.Message;
}
}
문제가 발생할 때 좀 더 자세히 설명해 주시겠습니까? 'btDelete_Click' 메서드가 호출되면 작동하지 않는다고 가정합니다. 그러나 예외를 게시 할 수 있습니까? –