藉助Web服務將文件上傳到Web服務器很容易。這是我一般這樣做的方式。這裏是我的示例代碼。如何開發Web服務(ASMX)上傳文件狀態
[WebMethod]
public bool UploadFile(string FileName, byte[] buffer, long Offset)
{
bool retVal = false;
try
{
// setting the file location to be saved in the server.
// reading from the web.config file
string FilePath =
Path.Combine(ConfigurationManager.AppSettings["upload_path"], FileName);
if (Offset == 0) // new file, create an empty file
File.Create(FilePath).Close();
// open a file stream and write the buffer.
// Don't open with FileMode.Append because the transfer may wish to
// start a different point
using (FileStream fs = new FileStream(FilePath, FileMode.Open,
FileAccess.ReadWrite, FileShare.Read))
{
fs.Seek(Offset, SeekOrigin.Begin);
fs.Write(buffer, 0, buffer.Length);
}
retVal = true;
}
catch (Exception ex)
{
//sending error to an email id
common.SendError(ex);
}
return retVal;
}
,但我想開發Web服務,這將給我的狀態以百分比上傳文件,當文件上傳將隨後完成活動將在客戶端與狀態消息文件是否被完全或不上傳被解僱。我也需要編寫可以同時處理多個請求的例程,並且例程必須是線程安全的。所以請指導我如何設計常規,這將滿足我所有的要求。謝謝
我需要開發Web服務,因爲Web服務可以從win和web這兩個應用程序中使用。所以我不在尋找jQuery Uploader和plUpload類插件。謝謝 – Thomas