利用SlickUpload上传文件
2006-01-15 17:24
316 查看
利用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"];
}
}
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);
}
}
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 articalhttp://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);
}
}
相关文章推荐
- 在ASP.NET中利用SlickUpload来上传大文件
- 在ASP.NET中利用SlickUpload上传大文件(续)
- 在ASP.NET中利用SlickUpload来上传大文件
- 在ASP.NET中利用SlickUpload来上传大文件
- 在ASP.NET中利用SlickUpload上传大文件
- 在ASP.NET中利用SlickUpload上传大文件(续)
- 在ASP.NET中利用SlickUpload来上传大文件
- 在ASP.NET中利用SlickUpload来上传大文件
- 利用Jakarta commons fileupload组件实现多文件上传
- jsp中如何利用jspsmartupload实现文件上传下载功能
- 利用Jakarta commons fileupload组件实现多文件上传
- 利用jsp+uploadify插件实现删除上传到ftp服务器里面的文件
- 利用Brettle.Web.NeatUpload控件对打文件进行上传(转)
- 利用Jakarta commons fileupload组件实现多文件上传(原理)
- struts利用插件jqueryupload上传文件,后台处理文件代码
- 大文件上传 之 改版了的SlickUpload.HttpUploadModule(Krystalware.SlickUpload.dll)
- 利用Jakarta commons fileupload组件实现多文件上传
- 利用jQuery-file-upload在MVC中实现上传文件(未完成)
- 利用flex+sevlet+fileupload组件实现文件的上传和下载
- Flex中利用FileReference类的browse()和upload()函数选择并上传单个文件到Web服务器