陈斌彬的技术博客

Stay foolish,stay hungry

Webservice-文件上传

[WebMethod]//文件上传
public string FJUpload(byte[] fs, string fileName)
{
    if (fileName.Length > 0)
    {
        MemoryStream m = new MemoryStream(fs);
        ///定义实际文件对象,保存上载的文件。
        FileStream f = new FileStream(HttpContext.Current.Server.MapPath("~") + "\\UploadFile\\" + fileName, FileMode.OpenOrCreate);
        ///把内内存里的数据写入物理文件
        m.WriteTo(f);
        m.Close();
        f.Close();
        f = null;
        m = null;

        return "UploadFile/" + fileName;
    }
    return "";
}

Resource Reference