以WebServices方式上传图片

主要代码:

    public string FileUploadImage(string ImagefileName, byte[] byteFileStream)

    {

        string mess = "";

        try

        {

            string filePath = HttpContext.Current.Server.MapPath("UploadFile/" + ImagefileName);

            FileStream fs = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.Write);

            BinaryWriter w = new BinaryWriter(fs);

            w.Write(byteFileStream);

            w.Flush();

            fs.Close();

        }

        catch (Exception eX)

        {

            mess = eX.Message;

        }



        if (mess != "")

        {

            return mess;

        }

        else

        {

            return "从服务器返回的消息:恭喜!文件   " + ImagefileName + "已成功上传!   返回时间为" + System.DateTime.Now.ToLongTimeString();

        }

    }

 

你可能感兴趣的:(WebServices)