Ejemplo n.º 1
0
        public static bool UploadImage(string base64String, string path, string fileName, string pageID, string ownerID, Boolean thumbnail = true)
        {
            bool flag = false;

            try
            {
                byte[] fs = Convert.FromBase64String(base64String);
                //fileName = Guid.NewGuid().ToString().Replace("-", "") + "." + fileName.Split('.')[1];

                //获取上传案例图片路径
                string fullpath = System.Web.HttpContext.Current.Server.MapPath(path);
                //string fullpath = @"D:\Work\yaodaibao\Code\Release\Files";/// 调试用
                if (!Directory.Exists(fullpath))
                {
                    Directory.CreateDirectory(fullpath);
                }
                //定义并实例化一个内存流,以存放提交上来的字节数组。
                MemoryStream m = new MemoryStream(fs);
                //定义实际文件对象,保存上载的文件。
                FileStream f = new FileStream(fullpath + "\\" + fileName, FileMode.Create);
                //把内内存里的数据写入物理文件
                m.WriteTo(f);

                if (thumbnail)
                {
                    System.Drawing.Image originalImage = System.Drawing.Image.FromStream(m);
                    System.Drawing.Image img           = GetThumbnail(originalImage, 80, 50);
                    img.Save(fullpath + "\\" + "T_" + fileName);
                    img           = null;
                    originalImage = null;
                }
                m.Close();
                f.Close();
                f = null;
                m = null;

                string sql = "";

                sql = "INSERT INTO Attachments(FPageID,FOwnerID,FFileName,FPath)VALUES('" + pageID + "','" + ownerID + "','" + fileName + "','" + path + "')";
                SQLServerHelper runner = new SQLServerHelper();
                runner.ExecuteSqlNone(sql);
                runner = null;
                flag   = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(flag);
        }
Ejemplo n.º 2
0
 public static void WriteToDB(string log, string type = "AppMessage", string caller = "", string method = "", string database = "yaodaibao")
 {
     try
     {
         string sql = "Insert Into " + database + ".dbo.AppLogs(FCaller,FMethod,FLog,FType)Values('{0}','{1}','{2}','{3}')";
         sql = string.Format(sql, caller, method, log.Replace("'", "''"), type);
         SQLServerHelper runner = new SQLServerHelper();
         runner.ExecuteSqlNone(sql);
         runner = null;
     }
     catch (Exception err)
     {
         throw err;
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// 保存文件
        /// </summary>
        /// <param name="base64String">文件base64</param>
        /// <param name="path">保存路径</param>
        /// <param name="fileID">文件ID</param>
        /// <param name="sql">保存完成之后需要执行的sql</param>
        /// <param name="connectStr">连接字符串</param>
        /// <returns></returns>
        public static bool UploadFile(string base64String, string path, long fileID, string sql = "", string connectStr = "")
        {
            bool flag = false;

            try
            {
                byte[] fs = Convert.FromBase64String(base64String);
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                //定义并实例化一个内存流,以存放提交上来的字节数组。
                MemoryStream m = new MemoryStream(fs);
                //定义实际文件对象,保存上载的文件。
                FileStream f = new FileStream(path + "\\" + fileID, FileMode.Create);
                //把内存里的数据写入物理文件
                m.WriteTo(f);
                m.Close();
                f.Close();
                f = null;
                m = null;
                if (sql != "" && connectStr != "")
                {
                    SQLServerHelper runner = new SQLServerHelper(connectStr);
                    runner.ExecuteSqlNone(sql);
                }
                else if (sql != "" && connectStr == "")
                {
                    SQLServerHelper runner = new SQLServerHelper();
                    runner.ExecuteSqlNone(sql);
                }
                flag = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(flag);
        }