在移动应用程序中创建文本文件 [英] Create text file in mobile application

查看:107
本文介绍了在移动应用程序中创建文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿所有
我正在Windows Mobile应用程序中工作,并且表单包含按钮...单击按钮时,我想在程序文件的应用程序文件夹中创建txt文件.

hey all
i am working in windows mobile application and have form contains button ... when button click i want to create txt file in the application folder in program file

../../Program Files/(ApplicationName)/(i need the file here)


我尝试使用此代码创建文件:


i tried this code to create file :

FileInfo MyFile = new FileInfo(@"..\..\Program Files\Beta1\ashraf.txt);
MyFile.Create();



但这回报期望IOEXEPCTION

任何想法??



but this return expection IOEXEPCTION

any idea ??

推荐答案

改用绝对路径,此示例对我有效:

Use an absolute path instead, this example works for me:

FileInfo file = new FileInfo("Program Files\\SmartDeviceProject1\\File.txt");
using (StreamWriter writer = file.CreateText())
{
    writer.WriteLine("FooBar");
}



希望这会有所帮助,
Fredrik



Hope this helps,
Fredrik


使用 Path.GetDirectoryName [^ ]方法和 Application.ExecutablePath [ ^ ]属性得到这个:
Use the Path.GetDirectoryName[^] method and the Application.ExecutablePath[^] property to get this:
string appPath = Path.GetDirectoryName(Application.ExecutablePath);


C :\ Documents and Settings \ Administrator \ Desktop \ Untitled 1.avi
C:\Documents and Settings\Administrator\Desktop\Untitled 1.avi


这篇关于在移动应用程序中创建文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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