方案一:
对应的解决方法可以参考:Dime Buffered Upload
http://www.codeproject.com/cs/webservices/DimeBufferedUpload.asp
源碼:Download source (WinForms, Web Service) - 545 Kb
Download demo app (WinForms, Web Service) - 493 Kb
Webservice:
public Service1()
{
InitializeComponent();
}
[WebMethod]
public string UploadFile(byte[] fs,string FileName)
{
try
{
MemoryStream m = new MemoryStream(fs);
//FileStream f = new FileStream(Server.MapPath(".") + "\\"+ FileName, FileMode.Create);
FileStream f = new FileStream(@"D:\"+ FileName, FileMode.Create); //這個路徑可以指定的,但是,一定要開放.Net寫的權限
m.WriteTo(f);
m.Close();
f.Close();
f = null;
m = null;
return "success !";
}
catch(Exception ex)
{
return ex.Message;
}
}
調用頁面
try
{
System.Web.HttpFileCollection oFiles;
oFiles = System.Web.HttpContext.Current.Request.Files;
string FilePath = oFiles[0].FileName;
string FileName = FilePath.Substring(FilePath.LastIndexOf("\\")+1);
WebReference.Service1 s1 = new com.foxconn.cr.CostomerRisk.WebReference.Service1();
byte[] b = new byte[oFiles[0].ContentLength];
System.IO.Stream fs;
fs = (System.IO.Stream)oFiles[0].InputStream;
fs.Read(b, 0, oFiles[0].ContentLength);
string tt = s1.UploadFile(b, FileName);
fs.Close();
}
catch(Exception ex)
{
this.L_msg.Visible=true;
this.L_msg.Text = ex.ToString();
}
浙公网安备 33010602011771号