通過自己上傳的每個文件轉至: 以下代碼檢查目錄是否存在,並提供文件寫入和讀取權限。
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