zoukankan      html  css  js  c++  java
  • 利用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);
       }
      }

  • 相关阅读:
    printFinal用法示例
    清瘦的记录者: 一个比dbutils更小巧、好用的的持久化工具
    requestAnimationFrame,Web中写动画的另一种选择
    深入理解定时器系列第二篇——被誉为神器的requestAnimationFrame
    Javascript 多线程?
    Expert 诊断优化系列------------------语句调优三板斧
    Appium+python自动化8-Appium Python API
    Selenium2+python自动化26-js处理内嵌div滚动条
    RobotFramework自动化4-批量操作案例
    RobotFramework自动化3-搜索案例
  • 原文地址:https://www.cnblogs.com/cy163/p/317661.html
Copyright © 2011-2022 走看看