Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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();


but this return expection IOEXEPCTION

any idea ??
Posted
Updated 16-Jun-10 2:13am
v2

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");
}


Hope this helps,
Fredrik
 
Share this answer
 
Comments
Ashraf ELHakim 16-Jun-10 8:31am    
Thx mr fredrik it is work fine :)
Use the Path.GetDirectoryName[^] method and the Application.ExecutablePath[^] property to get this:
C#
string appPath = Path.GetDirectoryName(Application.ExecutablePath);
 
Share this answer
 
Comments
Ashraf ELHakim 16-Jun-10 8:31am    
thx mr kiristian :) for ur quick replay
C:\Documents and Settings\Administrator\Desktop\Untitled 1.avi
 
Share this answer
 
XML
<!-- this script got from www.javascriptfreecode.com-Coded by: Krishna Eydat -->
<!-- Search Google -->
<center>
<FORM method=GET action="http://www.google.com/search">
<TABLE bgcolor="#FFFFFF"><tr><td>
<A HREF="http://www.google.com/">
<IMG SRC="http://www.google.com/logos/Logo_40wht.gif" <br></A>
<INPUT TYPE=text name=q size=31 maxlength=255 value="">
<INPUT TYPE=hidden name=hl value="en">
<INPUT type=submit name=btnG VALUE="Google Search">
</td></tr></TABLE>
</FORM>
</center>
<!-- Search Google -->

<font face="Tahoma"><a target="_blank" href="http://www.javascriptfreecode.com/"><span style="font-size: 8pt; text-decoration: none">JavaScript Free Code</span></a></font>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900