0
私はdropzoneを使用して複数のファイルをサーバーにアップロードしています。ファイルはサーバーにアップロードされ、ファイル名はテーブルに保存されます。単一セッション変数内に複数の値を格納および取得する方法
セッション中にファイル名を追加しようとしています。 ここでの問題は、それが単一セッション内で複数のファイル名を追加していないということです
ここに私のコードです:ここ
string imageSessList = context.Session["imageNames"].ToString(); //if i put this line at the begining, then the debugger doesn't even moves to foreach block
foreach (string s in context.Request.Files)
{
HttpPostedFile file = context.Request.Files[s];
string fileName = file.FileName;
string fileExtension = file.ContentType;
string strUploadFileExtension = fileName.Substring(fileName.LastIndexOf(".") + 1);
string strAllowedFileTypes = "***jpg***jpeg***png***gif***bmp***"; //allowed file types
string destFileName = "";
List<string> lstImageNames = new List<string>();
// else upload file
if (!string.IsNullOrEmpty(fileName))
{
if (strAllowedFileTypes.IndexOf("***" + strUploadFileExtension + "***") != -1) //check extension
{
if (context.Request.Files[0].ContentLength < 5 * 1024 * 1024) //check filesize
{
// generate file name
destFileName = Guid.NewGuid().ToString() + "." + strUploadFileExtension;
string destFilePath = HttpContext.Current.Server.MapPath("/resourceContent/") + destFileName;
//Save image names to session
lstImageNames.Add(destFileName);
context.Session["imageNames"] = lstImageNames;
file.SaveAs(destFilePath);
strMessage = "Success " + destFileName;
}
else
{
strMessage = "File Size can't be more than 5 MB.";
}
}
else
{
strMessage = "File type not supported!";
}
}
} // foreach
context.Response.Write(strMessage);
}
iは、複数のない、セッションにのみ、単一のファイル名を追加することができていますが。今そこに新しい項目を追加 context.Session [「imageNames」]
設定
。 次の行には移動しません。context.Session ["imageNames"] = lstImageNames; さらにセッションに値を追加しないので、次回のアップロード時にセッションが空になります – ace
@ace私の更新された回答を確認してください – Damith
はい、感謝しました – ace