• 上传文件到服务器


        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;
     
     
            }
  • 相关阅读:
    spring cloud项目搭建
    获取iframe的window对象
    数学杂谈 #7
    [AGC023D] Go Home
    JOISC 2021 部分题解
    [NOI2017]泳池
    [NOI2016] 循环之美
    [NOI2016] 优秀的拆分
    [LG P3676]小清新数据结构题
    [ARC113F]Social Distance
  • 原文地址:https://www.cnblogs.com/nayilvyangguang/p/9981580.html
Copyright © 2020-2023  润新知