admin 管理员组文章数量: 887007
c# 基于WebService的手机图片上传
WebService部分代码
public string UploadFile(byte[] fs, string FileName){try{///定义并实例化一个内存流,以存放提交上来的字节数组。MemoryStream m = new MemoryStream(fs);///定义实际文件对象,保存上载的文件。//FileStream f = new FileStream(Server.MapPath(".") + "\\image\\"FileStream f = new FileStream(@"E:\01\SmartDeviceProject1\WebService1\" + "\\image\\"+ FileName, FileMode.Create);///把内内存里的数据写入物理文件m.WriteTo(f);m.Close();f.Close();f = null;m = null;return "文件已经上传成功。";}catch (Exception ex){return ex.Message;}}
手机端图片文件打开上传代码
private void button1_Click_1(object sender, EventArgs e){openFileDialog1.InitialDirectory = GetStorageFolder();openFileDialog1.Filter = "jpg files(*.jpg)|*.jpg|gif files(*.gif)|*.gif|bmp files(*.bmp)|*.bmp|All files (*.*)|*.*";if (openFileDialog1.ShowDialog() == DialogResult.OK){Image img = new Bitmap(openFileDialog1.FileName);pictureBox1.Image = img;}}private void button2_Click(object sender, EventArgs e){//上传图片SmartDeviceProject1.localhost_uploadimage.Service1 uf = new Service1();FileInfo fi = new FileInfo(openFileDialog1.FileName);byte[] b = new byte[fi.Length];System.IO.FileStream fs = fi.OpenRead();fs.Read(b, 0, Convert.ToInt32(fi.Length));uf.UploadFile(b, "abc" + System.Guid.NewGuid() + ".jpg");}
本文标签: c 基于WebService的手机图片上传
版权声明:本文标题:c# 基于WebService的手机图片上传 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.freenas.com.cn/jishu/1732353022h1533630.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论