通过自己上传的每个文件转至: 以下代码检查目录是否存在,并提供文件写入和读取权限。
foreach (string file in context.Request.Files)
{
HttpPostedFile hpf = context.Request.Files[file] as HttpPostedFile;
string rootPathForwritingfile=AppDomain.CurrentDomain.BaseDirectory +"your destination folder name//"+Uri.UnescapeDataString(Path.GetFileName(hpf.FileName));
//check for the directory exists or not
FileStream fileStream = new FileStream(rootPathForwritingfile, FileMode.Create, FileAccess.ReadWrite);
ReadWriteStream(hpf.InputStream, fileStream);
}
private static void ReadWriteStream(Stream readStream, Stream writeStream)
{
int Length = 256;
Byte[] buffer = new Byte[Length];
int bytesRead = readStream.Read(buffer, 0, Length);
// write the required bytes
while (bytesRead > 0)
{
writeStream.Write(buffer, 0, bytesRead);
bytesRead = readStream.Read(buffer, 0, Length);
}
readStream.Close();
writeStream.Close();
}
**
检查使用 上传的Javascript文件之前存在编辑答案:
**
$('#<%=btnUpload.ClientId%>').click(function(e){
$.each($('#File1').files,function(index,file){
if(type of file !== 'undefined' && file.size > 0)
{
alert('success');
//do your stuff
}
else
{
alert('file not found');
//do your stuff for breaking the event and warn the user that the file specified was not found.
//try e.preventdefault();
}
});
});
如果您提供完整的代码,那将会很棒。 – RajeshKannan 2014-09-06 09:03:38
我加载了我的网页设计。 ![有效的XHTML](http://i57.tinypic.com/2qsrmvk.png)。通过按“添加更多文件”,用户可以选择多个文件,按“处理”键,即可启动处理文件。当本地计算机中不存在文件时,按“处理”键时,显示“未找到文件”。 – mansureh 2014-09-06 09:26:51