移动质监执法通项目用到如何实现拍照上传功能

移动质监执法通项目用到如何实现拍照上传功能,写了个简单的Sample.

WEBSERVICE接口:
    [WebMethod(Description = "上传照片")]
    public bool updatePhoto(string CheckRecordId, byte[][] b, string[] fileName)
    {
        try
        {
            //上传照片
            if (!(b == null || fileName == null))
            {
                for (int i = 0; i < b.Length; i++)
                {
                    if (b[i] != null && b[i].Length > 0 && fileName[i] != null && fileName[i] != string.Empty)
                    {

                        string filePath = System.Configuration.ConfigurationManager.AppSettings["PhotoFilePath"];
                        string filetypes = fileName[i].Substring(fileName[i].IndexOf('.') + 1);
                        filePath += DateTime.Now.ToString("yyyyMMddHHmmss") + "." + filetypes;
                        // filePath += fileName[i].ToString();


                        MemoryStream memoryStream = new MemoryStream(b[i]);
                        System.IO.FileStream fileStream = new System.IO.FileStream(filePath, FileMode.Create);
                        memoryStream.WriteTo(fileStream);
                        memoryStream.Close();
                        fileStream.Close();
                        memoryStream = null;
                        fileStream = null;

                        string url = "http://" + System.Configuration.ConfigurationManager.AppSettings["IP"] + "/" + DateTime.Now.ToString("yyyyMMddHHmmss") + "." + filetypes;
                        string sql = "update CheckRecord set cPhoto='" + url + "' where ID='" + CheckRecordId + "'";

                        SqlConnection cnn = new SqlConnection(ConnStr);
                        SqlCommand cmmd = new SqlCommand(sql, cnn);
                        cmmd.CommandType = CommandType.Text;
                        cnn.Open();
                        int y = cmmd.ExecuteNonQuery();
                        cnn.Close();
                    }
                }
            }
        }
        catch (Exception ex)
        {
            System.Diagnostics.Debug.WriteLine(ex.Message);
            return false;//"文件上传异常";
        }

        return true;//"文件上传成功";
    }

作者:欧宏远
博客:http://www.cnblogs.com/pdasoft
日期:2011年12月7日

 

转载于:https://www.cnblogs.com/pdasoft/archive/2011/12/07/2278729.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值