• 利用SlickUpload上传文件


    利用Session变量解决勇在LetterFolderCustomFileNameGenerator.cs文件内的GenerateFileName()函数动态碟成如 "P00001" "P01009"等样式的目录

     public string GenerateFileName(UploadedFile file)
      {
       //string fileName = Path.Combine(file.ClientName.Substring(0, 1).ToLower(), file.ClientName);
       //DirectoryInfo di = Directory.CreateDirectory(@"d:cnawebjournal-center.comXYZ");
       //CreateDirectory(HttpContext.Current.Server.MapPath("../") + HttpContext.Current.Request.QueryString["PaperIDID"]);
       
       CreateDirectory(HttpContext.Current.Server.MapPath("../") + HttpContext.Current.Session["FolderName"]);
       string fileName = Path.Combine((string)HttpContext.Current.Session["FolderName"], file.ClientName);
       return fileName;
      }

    在LetterFolderCustomFileNameGenerator.cs文件中直接使用Session["FolderName"]会发生错误,

    在文章http://dotnetspider.com/Question696.aspx找到答案

    Hi All
     i m new to asp.net, any help will be appriciated ,
    i have a login form where i get login/pass if success i generate two sessions like
    Session["EmailAddress"] = EmailAddress;
    Session["Name"] = Name;
    upto here its pretty ok .. i have a .cs class naming user.cs it has different methods like AdUser,updateUser etc

    the problem is that when ever i try to get the vale of session in this class it gives me this error : The name 'Session' does not exist in the class or namespace 'RMS.User'
    y the session varible is not visible here ? or what should i do to get its value

    Waiting 4 reply,
    Qazi Asim

    use this in your class files to access the session:
    HttpContext.Current.Session("EmailAddress")

    Example:


    public class user
    {
       public void MySessionValues()
       {
           string myEmailAddress = HTTPContext.Current.Session["EmailAddress"];
       }
    }

    利用SlickUpload上传文件的问题

    By using the CreateDirectory() function provided in the following artical

    http://www.codeproject.com/csharp/CreateDirectorymethod.asp

    now, we can create a new folder for uploading files.

    in LetterFolderCustomFileNameGenerator.cs, we add the function public static void CreateDirectory(string DirectoryPath)

    public class LetterFolderCustomFileNameGenerator : ICustomFileNameGenerator
     {
      public string GenerateFileName(UploadedFile file)
      {
       //string fileName = Path.Combine(file.ClientName.Substring(0, 1).ToLower(), file.ClientName);
       //DirectoryInfo di = Directory.CreateDirectory(@"d:\cna\web\journal-center.com\XYZ");
       CreateDirectory("d:\\cna\\web\\journal-center.com\\" + "XYZNow");
       string fileName = Path.Combine("XYZNow", file.ClientName);
       return fileName;
      }

      public static void CreateDirectory(string DirectoryPath)
      {
       // trim leading \ character
       DirectoryPath = DirectoryPath.TrimEnd(Path.DirectorySeparatorChar);
       Scripting.FileSystemObject fso = new Scripting.FileSystemObjectClass();
       // check if folder exists, if yes - no work to do
       if(!fso.FolderExists(DirectoryPath))
       {
        int i = DirectoryPath.LastIndexOf(Path.DirectorySeparatorChar);
        // find last\lowest folder name
        string CurrentDirectoryName = DirectoryPath.Substring(i+1,
         DirectoryPath.Length-i-1);
        // find parent folder of the last folder
        string ParentDirectoryPath = DirectoryPath.Substring(0,i);
        // recursive calling of function to create all parent folders
        CreateDirectory(ParentDirectoryPath);
        // create last folder in current path
        Scripting.Folder folder = fso.GetFolder(ParentDirectoryPath);
        folder.SubFolders.Add(CurrentDirectoryName);
       }
      }

  • 相关阅读:
    explain详解与索引最佳实践
    MySQL的配置文件
    MySQL索引数据结构红黑树,Hash,B+树详解
    elasticsearch 进阶
    淘宝服务端高并发分布式架构演进之路
    http请求的header的一个小细节
    一次解决idea maven settings.xml文件不生效
    SpringBoot dev-tools vjtools dozer热启动类加载器不相同问题
    spring boot eclipse 远程调试
    vscode 同步配置
  • 原文地址:https://www.cnblogs.com/cy163/p/317661.html
Copyright © 2020-2023  润新知