在网站的当前目录中创建文件的问题 [英] problem with creating a file in current directory of website

查看:83
本文介绍了在网站的当前目录中创建文件的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过C#的System.IO.FileStream(在asp.net中)创建一个文件,在我的网站的根目录中,在webserver(托管网络服务器)中,或者可能更好地说网站的根目录。

怎么可能?

解决方案

这样的事情:



< pre lang =vb> string appPath = Request.PhysicalApplicationPath;
string filePath = appPath + 文本。 TXT;
StreamWriter w;
w = File.CreateText(filePath);
w.WriteLine( 这是一条测试线。);
w.WriteLine( 这是另一条线。);
w.Flush();
w.Close();







顺便说一句,我不建议写它在您的网站的根目录中,因为该进程需要写入权限。最好创建一个子目录并在那里编写文件。


I want to create a file through System.IO.FileStream of C#(in asp.net) , in the root directory of my website in the webserver(hosting webserver)or may be it's better to say root directory of website.
how it's possible?

解决方案

Something like this:

string appPath = Request.PhysicalApplicationPath;
        string filePath = appPath + "Text.txt";
        StreamWriter w;
        w = File.CreateText(filePath);
        w.WriteLine("This is a test line.");
        w.WriteLine("This is another line.");
        w.Flush();
        w.Close();




Btw, I would not recommend to write it in the root of your website as the process would need write permissions. It's better to create a sub directory and write your files there.


这篇关于在网站的当前目录中创建文件的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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