我想做一个Web Services,其功能是实现文件的上传,现在做了一个,其思想是:用户给出文件的Bace64码和文件名,然后我再转换成文件写入wwwroot,大概像这样:
[WebMethod]
public bool FileTran(string file, string name)
{
byte[] buf = System.Convert.FromBase64String(file);
System.IO.FileStream fs = System.IO.File.OpenWrite(Server.MapPath(@"\" + name));
System.IO.BinaryWriter w = new System.IO.BinaryWriter(fs);
try
{
w.Write(buf);
}
catch(Exception)
{
return false;
}
finally
{
w.Flush();
fs.Close();
}
return true;
}
但是调用时总是说对路径访问没有权限,这是怎么回事??
请高手执教!
还有没有别的方法实现这个功能???
[WebMethod]
public bool FileTran(string file, string name)
{
byte[] buf = System.Convert.FromBase64String(file);
System.IO.FileStream fs = System.IO.File.OpenWrite(Server.MapPath(@"\" + name));
System.IO.BinaryWriter w = new System.IO.BinaryWriter(fs);
try
{
w.Write(buf);
}
catch(Exception)
{
return false;
}
finally
{
w.Flush();
fs.Close();
}
return true;
}
但是调用时总是说对路径访问没有权限,这是怎么回事??
请高手执教!
还有没有别的方法实现这个功能???
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货