WebServiceアップロード画像
WebService:
/// <summary>
///
/// </summary>
/// <param name="fileBytes"></param>
/// <param name="fileName"></param>
/// <returns></returns>
[WebMethod(Description = " .")]
public string UploadFile(byte[] fileBytes, string fileName)
{
try
{
MemoryStream memoryStream = new MemoryStream(fileBytes); //1. , 。
FileStream fileUpload = new FileStream(Server.MapPath(".") + "\\" + fileName, FileMode.Create); ///2. , 。
memoryStream.WriteTo(fileUpload); ///3.
memoryStream.Close();
fileUpload.Close();
fileUpload = null;
memoryStream = null;
return " ";
}
catch (Exception ex)
{
return ex.Message;
}
}
クライアントコール: private void BtnUpLoadImg_Click(object sender, EventArgs e)
{
ImgService.ImgService uf = new ImgService.ImgService();
FileInfo imgFile = new FileInfo(@"D:\ \ \1_110508104158_7.jpg");
byte[] imgByte = new byte[imgFile.Length];//1.
System.IO.FileStream imgStream = imgFile.OpenRead();//2.
imgStream.Read(imgByte, 0, Convert.ToInt32(imgFile.Length));//3.
MessageBox.Show(uf.UploadFile(imgByte, "abc" + System.Guid.NewGuid() + ".jpg"));//4.
}