Exemplo n.º 1
0
        //private static Client.ChatCallBack callBack = new Client.ChatCallBack();
        //private static InstanceContext instance = new InstanceContext(callBack);
        /// <summary>
        /// 将服务器上的某个文件下载到本地
        /// </summary>
        /// <param name="ServerName"></param>
        /// <param name="oldName">文件名,該文件保存到Tem文件夾下</param>
        /// <returns></returns>
        public static string DownLoad(string ServerName, string oldName)
        {
            string strDir = "";

            try
            {
                Client.ServiceReference1.FileTransportServiceClient ftc = new Client.ServiceReference1.FileTransportServiceClient();
                Stream fileStream = ftc.GetFile(ServerName);
                ftc.Close();
                //fileTransportServiceClient.Close();
                if (fileStream.CanRead)
                {
                    Int32      count        = 0;
                    byte[]     buffer       = new byte[4096];
                    FileStream targetStream = new FileStream(BasicClass.BasicFile.Dir + oldName, FileMode.Create, FileAccess.Write, FileShare.None);
                    while ((count = fileStream.Read(buffer, 0, 4096)) > 0)
                    {
                        targetStream.Write(buffer, 0, count);
                    }
                    fileStream.Close();
                    targetStream.Close();
                    targetStream = null;
                    targetStream = null;
                    strDir       = oldName;
                }
            }
            catch (Exception ex)
            {
            }
            return(strDir);
        }
Exemplo n.º 2
0
 /// <summary>
 /// 删除服务器上的某个文件
 /// </summary>
 /// <param name="FileName"></param>
 /// <returns></returns>
 public static string DelFile(string FileName)
 {
     Client.ServiceReference1.FileTransportServiceClient ftc = new Client.ServiceReference1.FileTransportServiceClient();
     try
     {
         //FileTransportServiceClient fileTransportServiceClient = new FileTransportServiceClient();
         ftc.DelFile(FileName);
         //fileTransportServiceClient.Close();
         return("OK");
     }
     catch
     {
         return("Error");
     }
     finally
     {
         ftc.Close();
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// 将byte[]形式的图片,保存为当前时间命名的jpg文件并上传到服务器
        /// </summary>
        /// <param name="bb"></param>
        /// <param name="SevName"></param>
        /// <returns></returns>
        public static string UpFile(byte[] bb, string SevName)
        {
            string newfilename = "";

            Client.ServiceReference1.FileTransportServiceClient ftc = new Client.ServiceReference1.FileTransportServiceClient();
            try
            {
                if (!Directory.Exists(BasicFile.Dir))
                {
                    Directory.CreateDirectory(BasicFile.Dir);
                }
                //FileTransportServiceClient fileTransportServiceClient = new FileTransportServiceClient();
                if (SevName == "")
                {
                    newfilename = DateTime.Now.ToString("yyMMddhhmmss") + DateTime.Now.Millisecond.ToString() + ".jpg";
                }
                else
                {
                    newfilename = SevName;
                }
                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();
                filestream.Close();
                filestream.Dispose();
                stream = null;
                return(newfilename);
            }
            catch
            {
                return("Error");
            }
            finally
            {
                ftc.Close();
            }
        }
Exemplo n.º 4
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();
            }
        }