C# 为什么要列出<&燃气轮机;是否不在此代码中填充?
我试图在字符串列表中填充文件路径C# 为什么要列出<&燃气轮机;是否不在此代码中填充?,c#,asp.net,ajax,dropzone.js,C#,Asp.net,Ajax,Dropzone.js,我试图在字符串列表中填充文件路径list img=new list()当客户端使用dropzone js发布文件时 上传的文件没有例外,但列表不会填充,有什么办法解决这个问题吗 protected void Page_Load(object sender, EventArgs e) { var httpRequest = System.Web.HttpContext.Current.Request; HttpFileCollection uploadFiles = httpReq
list img=new list()代码>当客户端使用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];
}
}
受保护的无效页面加载(对象发送方,事件参数e)
{
var httpRequest=System.Web.HttpContext.Current.Request;
HttpFileCollection uploadFiles=httpRequest.Files;
List img=新列表();
如果(iPostBack)
{
如果(httpRequest.Files.Count>0)
{
int i;
对于(i=0;i
我从
页面中的js(根据他们的演示)是
//来自服务器的文件上载响应
Dropzone.options.dropzoneForm={
maxFiles:2,
url:“WebFormDropzoneDemo.aspx”,
init:函数(){
此.on(“MaxFilesExcepended”)函数(数据){
var res=eval('('+data.xhr.responseText+');
});
this.on(“addedfile”,函数(文件){
//创建删除按钮
var removeButton=Dropzone.createElement(“删除文件”);
//将Dropzone实例捕获为闭包。
var_this=这个;
//收听单击事件
removeButton.addEventListener(“单击”),函数(e){
//确保单击按钮不会提交表单:
e、 预防默认值();
e、 停止传播();
//删除文件预览。
_此.removeFile(文件);
//如果还要删除服务器上的文件,
//您可以在这里执行AJAX请求。
});
//将按钮添加到文件预览元素。
file.previewElement.appendChild(removeButton);
});
}
};
这会很好地填充Request.Files
public partial class WebFormDropzoneDemo : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
SaveUploadedFile(Request.Files);
}
}
public void SaveUploadedFile(HttpFileCollection httpFileCollection)
{
bool isSavedSuccessfully = true;
string fName = "";
foreach (string fileName in httpFileCollection)
{
HttpPostedFile file = httpFileCollection.Get(fileName);
//Save file content goes here
fName = file.FileName;
if (file != null && file.ContentLength > 0)
{
var originalDirectory = new DirectoryInfo(string.Format("{0}Images\\WallImages", Server.MapPath(@"\")));
string pathString = System.IO.Path.Combine(originalDirectory.ToString(), "imagepath");
var fileName1 = Path.GetFileName(file.FileName);
bool isExists = System.IO.Directory.Exists(pathString);
if (!isExists)
System.IO.Directory.CreateDirectory(pathString);
var path = string.Format("{0}\\{1}", pathString, file.FileName);
file.SaveAs(path);
}
}
//if (isSavedSuccessfully)
//{
// return Json(new { Message = fName });
//}
//else
//{
// return Json(new { Message = "Error in saving file" });
//}
}
}
公共部分类WebFormDropzoneDemo:System.Web.UI.Page
{
受保护的无效页面加载(对象发送方、事件参数e)
{
如果(!IsPostBack)
{
保存上传文件(Request.Files);
}
}
public void SaveUploadedFile(HttpFileCollection HttpFileCollection)
{
bool isSavedSuccessfully=true;
字符串fName=“”;
foreach(httpFileCollection中的字符串文件名)
{
HttpPostedFile file=httpFileCollection.Get(文件名);
//保存文件内容到这里
fName=file.FileName;
如果(file!=null&&file.ContentLength>0)
{
var originalDirectory=newdirectoryinfo(string.Format(“{0}Images\\wallmages”,Server.MapPath(@“\”));
string Path string=System.IO.Path.Combine(originalDirectory.ToString(),“imagepath”);
var fileName1=Path.GetFileName(file.FileName);
bool isExists=System.IO.Directory.Exists(路径字符串);
如果(!isExists)
System.IO.Directory.CreateDirectory(路径字符串);
var path=string.Format(“{0}\\{1}”,路径字符串,文件名);
file.SaveAs(路径);
}
}
//如果(成功保存)
//{
//返回Json(新的{Message=fName});
//}
//否则
//{
//返回Json(新的{Message=“保存文件时出错”});
//}
}
}
我从一家公司管理他们的项目
页面中的js(根据他们的演示)是
//来自服务器的文件上载响应
Dropzone.options.dropzoneForm={
maxFiles:2,
url:“WebFormDropzoneDemo.aspx”,
init:函数(){
此.on(“MaxFilesExcepended”)函数(数据){
var res=eval('('+data.xhr.responseText+');
});
this.on(“addedfile”,函数(文件){
//创建删除按钮
var removeButton=Dropzone.createElement(“删除文件”);
//将Dropzone实例捕获为闭包。
var_this=这个;
//收听单击事件
removeButton.addEventListener(“单击”),函数(e){
//确保单击按钮不会提交表单:
e、 预防默认值();
e、 停止传播();
//删除文件预览。
_此.removeFile(文件);
//如果还要删除服务器上的文件,
//您可以在这里执行AJAX请求。
});
//将按钮添加到文件预览元素。
file.previewElement.appendChild(removeButton);
});
}
};
这将填充Request.Files
public partial class WebFormDropzoneDemo : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
SaveUploadedFile(Request.Files);
}
}
public void SaveUploadedFile(HttpFileCollection httpFileCollection)
{
bool isSavedSuccessfully = true;
string fName = "";
foreach (string fileName in httpFileCollection)
{
HttpPostedFile file = httpFileCollection.Get(fileName);
//Save file content goes here
fName = file.FileName;
if (file != null && file.ContentLength > 0)
{
var originalDirectory = new DirectoryInfo(string.Format("{0}Images\\WallImages", Server.MapPath(@"\")));
string pathString = System.IO.Path.Combine(originalDirectory.ToString(), "imagepath");
var fileName1 = Path.GetFileName(file.FileName);
bool isExists = System.IO.Directory.Exists(pathString);
if (!isExists)
System.IO.Directory.CreateDirectory(pathString);
var path = string.Format("{0}\\{1}", pathString, file.FileName);
file.SaveAs(path);
}
}
//if (isSavedSuccessfully)
//{
// return Json(new { Message = fName });
//}
//else
//{
// return Json(new { Message = "Error in saving file" });
//}
}
}