根据在文本框中输入的日期创建日期月份和年份的子文件夹 [英] Creating sub folders for date month and year based on the date entered in textbox

查看:82
本文介绍了根据在文本框中输入的日期创建日期月份和年份的子文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用带日期选择器的文本框来选择日期,并根据所选日期,当我点击go按钮时,应在FTP文件夹中为文件框中给出的日期,月份和年份创建子文件夹。这应该用windows应用程序来完成你能告诉我我该怎么做。



我尝试过的事情:



以下是我用来显示所选日期的代码

I need to use a text box with date picker to select the date and based on the selected date when i click on go button sub folders should be created in FTP Folder for that date,month and year that is given in text box.This should be done using windows application can you please tell me how can i do this.

What I have tried:

Below is the code that i had used to display the selected date

public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            dateTimePicker1.Format = DateTimePickerFormat.Short;
            dateTimePicker1.Value = DateTime.Today;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            DateTime iDate;
            iDate = dateTimePicker1.Value;
            string theDate = dateTimePicker1.Value.ToString("MM-dd-yyyy");
            CreateDirectoryFTP(directory);

        }  



和在ftp文件夹中创建子文件夹的代码是




and the code to create sub folders in ftp folder is

using System.Net;

private void CreateDirectoryFTP(string directory)
{
    string path = @"/" + directory;
    WebRequest request = WebRequest.Create(FtpHost + path);
    request.Method = WebRequestMethods.Ftp.MakeDirectory;
    request.Credentials = new NetworkCredential(FtpUser, FtpPass);
    try
    {
       request.GetResponse();
    }
    catch (Exception e)
    {
        //directory exists
    }
}



点击后使用此功能在按钮上我无法在ftp文件夹中创建文件夹如何在ftp文件夹中创建所选日期,月份和年份的文件夹


after using this when i click on button i am unable to create folders in ftp folder how can i create folders for selected date,month and year in ftp folder

推荐答案

System.DateTime myDate = DateTime.Now;
int year = myDate.Year;
int month = myDate.Month;
int day = myDate.Day;
int hour = myDate.Hour;

string dayName = myDate.DayOfWeek


这篇关于根据在文本框中输入的日期创建日期月份和年份的子文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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