如何将动态创建的.html文件保存到C#的根目录中 [英] How to save dynamically created .html file into root directory in C#

查看:263
本文介绍了如何将动态创建的.html文件保存到C#的根目录中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是C#的新手,我在C#中创建.html文件,但我不知道如何保存在根目录(即DateTimeStamp创建的文件夹)中,请建议我如何保存文件在给定的难治,我的代码是

Hi, I am new to C#,I am creating the .html file in C#, but i don't have any idea how to save in root directory(i.e Folder created by DateTimeStamp),Please suggest me how to save file in given diractory ,my code is

filename = String.Concat(Headline,".html");

     DateTimeStamp = DateTime.Now.Day.ToString() + DateTime.Now.Month.ToString() +    DateTime.Now.Year.ToString();

     if (!Directory.Exists(DateTimeStamp))
     {
         Directory.CreateDirectory(Server.MapPath(DateTimeStamp));
     }

推荐答案

参考 - Directory.CreateDirectory Method(String) [ ^ ]

Refer - Directory.CreateDirectory Method (String)[^]
Quote:

创建指定路径中的所有目录和子目录。

Creates all directories and subdirectories in the specified path.



因此,当您编写以下代码时......


So, when you write the following code...

Directory.CreateDirectory(Server.MapPath(DateTimeStamp));



它创建一个目录名称为 DateTimeStamp



只是意味着它会创建一个文件夹名称作为包含的值在网站根文件夹中的 DateTimeStamp 中。它无法为您创建文件。


It creates a Directory Name as DateTimeStamp.

Simply it means that it will create a folder name as the value contained in DateTimeStamp inside Website Root folder. It can't create the file for you.


这篇关于如何将动态创建的.html文件保存到C#的根目录中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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