filestream提到文件夹路径 [英] filestream mention the folder path

查看:105
本文介绍了filestream提到文件夹路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



当我使用文件流时,我们应该提及以下代码("C:\ Variables.txt",...)的文件夹路径

将Dim fs作为新FileStream("c:\ Variables.txt",FileMode.Append,FileAccess.Write,FileShare.Write.


但是,我想在创建文件夹中的任何位置存储驱动器名称,而无需提及.
就像filestream(〜\ LogFile \ Variables.txt",.....).

请给我正确的映射路径语法,如上.

谢谢.

Hi,

When i use filestream we should mention the folder path as below code ("C:\Variables.txt",...)

Dim fs As New FileStream("c:\Variables.txt", FileMode.Append, FileAccess.Write, FileShare.Write.


But, i want to store in without mentiong the drive name anywhere in the created folder.
like filestream("~\LogFile\Variables.txt",.....).

pls. give me the correct syntax for the map path as above.

Thanks.

推荐答案

好吧,您试图将文件保存在绝对路径中.但是,如果需要保存它的相对路径,则需要在网站中创建一个文件夹,或者需要使用网站的根文件夹.我放了一些可能需要看一下的代码片段.

Well, you were trying to save the file in absolute path. But if you need to save it relative path, you need to create a folder in your web site or you need to use your root folder of the web site. I put some code snippet that may need to look it.

string path = Server.MapPath("~");// Maps the root web site folder


string path = Server.MapPath("~/LogFile");// Will map a folder name called LogFile in your website.




希望对您有所帮助.




I hope this will help you well.


请参阅此链接以获取路径基础知识

http://stackoverflow.com/questions/275781/server-mappath- server-mappath-server-mappath-server-mappath [ ^ ]
see this link to get path basics

http://stackoverflow.com/questions/275781/server-mappath-server-mappath-server-mappath-server-mappath[^]


我怀疑问题的根源在于绝对路径和相对路径之间的争议.您需要保留除卷以外的几乎所有绝对路径.这与相对路径完全相同,但相对于卷根.

在代码中同时使用相对和绝对方法是错误的.请参阅我最近的回答,在其中我解释如何使用文件路径的想法:
如何从以下位置访问文件根目录根目录的html文件夹 [
I suspect the root of your problem is controversy between absolute path and relative path. You need to keep almost all of the absolute path except the volume. This is simply the same as relative path but relative to the volume root.

Using both relative and absolute approached in code is wrong. Please see my recent answer where I explain the idea how to work with file paths:
How to access a file from html folder of root directoty[^].

Hope it can help you.

—SA


这篇关于filestream提到文件夹路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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