我想问一下如何返回字符串的路径?我有这个错误消息
'_ Default.uploadfile(string,string)':并非所有代码路径都返回值
private string uploadfile(String filetype, String Uploadfilename)
{
String csFileUploadName;
if (filetype == "FiUptrack")
{
csFileUploadName = "C:\\MusicStore\\uploads\\promos\\" + Uploadfilename;
}
else
{
csFileUploadName = "C:\\MusicStore\\uploads\\images\\" + Uploadfilename;
}
try
{
FiUptrack.SaveAs(csFileUploadName);
lblRequired.Text = "Upload status: File uploaded!";
return csFileUploadName.ToString();
}
catch (Exception ex)
{
lblRequired.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
}
}
用法:
csArtworkupload = uploadfile("Artworkupload", FiUptrack.FileName);
csArtworkupload是一个字符串
答案 0 :(得分:4)
正如错误消息明确指出的那样,您的方法并不总是返回任何内容。
具体而言,如果抛出异常,则不会执行return
语句。
答案 1 :(得分:1)
该错误是因为您没有在代码中的所有执行路径中返回 - 即某些分支不会导致返回。
尝试将其放在代码的末尾:
return csArtworkupload;