使用文件名创建动态文件夹 [英] Creating the dynamic folder using filename

查看:93
本文介绍了使用文件名创建动态文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
当我使用dotnet中的浏览功能从本地文件夹中选择单词或图像时,如果单击提交按钮,则应创建新文件夹(名称应为当前月份的文件名),文件应存储在该新文件夹中. br/>
例如,我的文件夹将是-images/

如果我要上传单词或图像-图像应这样存储(images/february/ws.doc).


谁能帮我做

hi guys,
when i select the word or image from the local folder using browse in dotnet and if i click the submit button it should create the new folder (the name should be filename with current month) and the files should be stored within that new folder.

for eg, my folder will be - images/

if i want to upload the word or images - the images should be stored like this (images/february/ws.doc).


can anyone help me to do

推荐答案

尝试类似的方法:

Try something like:

void Save(string sourceFilePath, string destinationRootDirectory)
{
    //create the destination directory
    string currentMonth = DateTime.Now.ToString("MMMM");
    string destinationDirectory = destinationRootDirectory + @"\images\" + currentMonth;
    Directory.CreateDirectory(destinationDirectory);

    //copy the source file to that directory
    string shortFileName = Path.GetFileName(sourceFilePath);
    string destinationFilePath = destinationDirectory + @"\" + shortFileName;
    File.Copy(sourceFilePath, destinationFilePath);
}


要实现Olivier Levrey描述的方法,您可能需要使用
您还需要确保Web应用程序的IIS用户上下文具有操作文件系统所需的访问权限.

问候
Espen Harlinn
To implement the methods described by Olivier Levrey, you will probably need to use HttpServerUtility.MapPath[^] to get a physical path for your files. Put a ''/'' at the beginning of the path to indicate an absolute virtual path to the site.

You will also need to ensure that the IIS user context for your web application has the required access rights to manipulate the filesystem.

Regards
Espen Harlinn


这篇关于使用文件名创建动态文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆