写输出目录,exe文件是从打开 [英] writing output to directory where exe is opened from

查看:121
本文介绍了写输出目录,exe文件是从打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表格 exe文件。现在点击链接,我想这将文件保存到它已经从,例如打开如果我给这个 exe文件给你,你把它复制到C盘的文件夹名为LA-LA,然后将其保存文件到C盘的文件夹名称香格里拉香格里拉。



目前,我想这里面工作,但我不希望它提供目录的路径了,

  myVar.Save(@C:\lala\test.xml); 



我可以使用哪些使用的.Net 2.0。


解决方案

  myVar.Save(@的test.xml); 

这应该写的test.xml 来的。目录你的EXE运行从



请注意,在写入的情况下,C:\ 根文件夹可能需要升高。管理员权限



您没有指定myVar的类型,但是这可能会有所帮助:

 使用System.IO; 

类节目
{
静态无效的主要(字串[] args)
{
File.WriteAllText(HelloWorld的,的test.txt );
}
}

这将创建的test.txt 的HelloWorld 内容文件,该文件被保存在可执行
目录。


I have a form exe. now on button click i want it to save a file to where it has been opened from, e.g. if i give this exe to you and you copy it to c drive folder name "la-la" then it save file to c drive folder name la-la.

At the moment I am trying this which works but I don't want it to provide path to directory anymore,

 myVar.Save(@"C:\lala\test.xml");

What can I use using .Net 2.0.

解决方案

myVar.Save(@"test.xml");

This should write test.xml to the directory your exe runs from.

Note that in case of writing to c:\ root folder might require elevated administrator permissions.

You didn't specify the type of myVar, but this might be helpful:

using System.IO;

class Program
{
    static void Main(string[] args)
    {
        File.WriteAllText("HelloWorld", "test.txt");
    }
}

This creates test.txt file with HelloWorld content, the file is saved in the executable directory.

这篇关于写输出目录,exe文件是从打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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