1
我想填充文件路徑的字符串列表List<string> img = new List<string>();
當有文件張貼由客戶端使用dropzone js 有沒有例外的文件上傳,但列表將不會填充,任何想法來解決這個問題?爲什麼列表<>不在此代碼中填充?
protected void Page_Load(object sender, EventArgs e)
{
var httpRequest = System.Web.HttpContext.Current.Request;
HttpFileCollection uploadFiles = httpRequest.Files;
List<string> img = new List<string>();
if (IsPostBack)
{
if (httpRequest.Files.Count > 0)
{
int i;
for (i = 0; i < uploadFiles.Count; i++)
{
HttpPostedFile postedFile = uploadFiles[i];
int fileSizeInBytes = postedFile.ContentLength;
string fileName = postedFile.FileName;// Request.Headers["X-File-Name"];
string fileExtension = "";
fileExtension = Path.GetExtension(fileName);
string savedFileName = Guid.NewGuid().ToString() + fileExtension;
string path = HttpContext.Current.Server.MapPath("~/img/items/");
string filename = path + savedFileName;
postedFile.SaveAs(filename);
img.Add(filename);
}
itm.img1 = img[0];
}
}
運行代碼後'img.Count'的值是多少?你怎麼知道它不會填充?你有例外嗎?需要更多信息。 –
@LukePark好的我會編輯我的問題 – ajjawi
@LukePark運行此代碼後,@ imke.Count'爲0 – ajjawi