zoukankan      html  css  js  c++  java
  • 上传文件到服务器

        public string SaveServerFile(string tempfilename, string filepath, string filename, bool isLocal = false)
            {
                #region MyRegion
                bool UseWeb = bool.Parse(ConfigurationManager.AppSettings["WebFileService"]);
     
                //判断是否启用文件服务器
                if (UseWeb && !isLocal)
                {
                    //存储临时文件
                    string uri = GetBaseServerSaveFilePath() + filepath;
                    string urishow = GetBaseServerFilePath() + filepath;
     
                    try
                    {
                        if (uri.StartsWith("http"))
                        {
                            WebClient webClient = new WebClient();
                            webClient.UploadFile(uri, "POST", tempfilename);
                            File.Delete(tempfilename);//删除临时上传文件
                            return urishow;
                        }
                        else
                        {
                            string userName = ConfigurationManager.AppSettings["ftpuser"];
                            string userPwd = ConfigurationManager.AppSettings["ftppwd"];
     
                            FtpHelper webClient = new FtpHelper(uri, userName, userPwd);
                            webClient.Upload(tempfilename);
                            //File.Delete(tempfilename);//删除临时上传文件
                            return urishow;
                        }
                    }
                    catch (Exception exception)
                    {
                        return exception.Message;
                    }
                }
                else
                {
                    if (!filepath.EndsWith("/"))
                    {
                        // filepath += "/";
                    }
                    string savefile = GetBaseServerFilePath(isLocal);
                    if (!savefile.EndsWith("/") || (filepath.IsNotNullOrEmpty() && !filepath.StartsWith("/")))
                
                        savefile += filepath;
                    if (!Directory.Exists(savefile))
                        Directory.CreateDirectory(savefile);
                    savefile += filename;
                    filepath += savefile;
                 
                }
     
                #endregion
     
                return filepath;
     
     
            }
  • 相关阅读:
    打开外部程序
    检测是否渲染
    maxsxript 坐标转换 函数
    实用 SQL 语句
    【整理】一些有用的学习资源链接
    关于 static 和 final 的一些理解
    Java8新特性时间日期库
    推荐一套后台管理系统
    Java API 之 Object
    【软件体系结构】架构风格与基于网络应用软件的架构设计
  • 原文地址:https://www.cnblogs.com/nayilvyangguang/p/9981580.html
Copyright © 2011-2022 走看看