Exemplo n.º 1
0
        /// <summary>
        /// 将byte[]形式的图片,保存为以当前时间命名的jpg文件,和"Mini"开头的缩略头
        /// </summary>
        /// <param name="bb"></param>
        /// <returns></returns>
        public static string SavePic(byte[] bb)
        {
            string newfilename = "";

            try
            {
                if (!Directory.Exists(BasicFile.Dir))
                {
                    Directory.CreateDirectory(BasicFile.Dir);
                }
                //FileTransportServiceClient fileTransportServiceClient = new FileTransportServiceClient();
                Client.ServiceReference1.FileTransportServiceClient ftc = new Client.ServiceReference1.FileTransportServiceClient();
                newfilename = DateTime.Now.ToString("yyMMddhhmmss") + DateTime.Now.Millisecond.ToString() + ".jpg";
                string     dir    = BasicFile.Dir + newfilename;
                FileStream stream = new FileStream(dir, FileMode.OpenOrCreate);
                stream.Write(bb, 0, bb.Length);
                stream.Close();
                stream.Dispose();
                FileStream filestream = new FileStream(dir, FileMode.Open, FileAccess.Read);
                ftc.UploadFile(newfilename, filestream);
                //fileTransportServiceClient.Close();
                //  GenThumbnail(filestream, BasicFile.Dir + "Mini" + newfilename);
                filestream.Close();
                filestream.Dispose();
                stream = null;
                return(newfilename);
            }
            catch
            {
                return("Error");
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 将本地文件以当前时间重命名上传到服务器
        /// </summary>
        /// <param name="OldName"></param>
        /// <param name="SevName"></param>
        /// <returns></returns>
        public static string UpFile(string OldName, string SevName)
        {
            string fileType    = "";
            string sortName    = "";
            string newfilename = "";

            Client.ServiceReference1.FileTransportServiceClient ftc = new Client.ServiceReference1.FileTransportServiceClient();
            try
            {
                FileStream stream = new FileStream(OldName, FileMode.Open, FileAccess.Read);
                sortName = OldName.Substring(OldName.LastIndexOf(@"\") + 1);
                if (SevName == "")
                {
                    if (OldName.IndexOf(".") != -1)
                    {
                        fileType = OldName.Substring(OldName.LastIndexOf(".")).ToLower();
                    }
                    newfilename = DateTime.Now.ToString("yyMMddhhmmss") + DateTime.Now.Millisecond.ToString() + fileType;
                }
                else
                {
                    newfilename = SevName;
                }
                ftc.UploadFile(newfilename, stream);
                //fileTransportServiceClient.Close();
                stream.Close();
                stream.Dispose();
                stream = null;
                return(sortName + "," + newfilename + "," + fileType);
            }
            catch
            {
                return("Error");
            }
            finally
            {
                ftc.Close();
            }
        }