![]() |
![]() |
![]() |
|||||
![]() |
![]() |
![]() |
![]() |
![]() |
|||
| Welcome
to Tech Support Forum home to more then 136,000 problems solved. Issues
have included: Spyware, Malware, Virus Issues, Windows, Microsoft,
Linux, Networking, Security, Hardware, and Gaming Getting your
problem solved is as easy as: 1. Registering for a free account 2. Asking your question 3. Receiving an answer Registered members: * See fewer ads. * And much more..
|
| Want to know how to post a question? click here | Having problems with spyware and pop-ups? First Steps |
|
|||||||
| Programming A discussion forum for programs and programming used in tech-related businesses. |
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 (permalink) | |
|
Registered User
Join Date: May 2008
Posts: 6
OS: winXP SP2 (switching to linux)
|
C# Error while trying to create text file
hey, i dont know if this is the right forum, so sorry if its not.
so im doing this project for school, im doing a Check Mate Game and im having a problem: when im trying to create a Text File im getting this error: Quote:
Code:
public void WriteToFile()
**
SW = File.CreateText("D:\\Projects\\Meydan\\Chess\\Saves");
for (int i = 0; i < 8; i++)
**
for (int j = 0; j < 8; j++)
**
SW.WriteLine("Index_i"); // המיקום במערך של המשבצת
SW.WriteLine(i.ToString());
SW.WriteLine("Index_j"); // המיקום במערך של המשבצת
SW.WriteLine(j.ToString());
//-------------------------------------------------
SW.WriteLine("Empty"); // סימון שאומר שמתחת לשורה זו יהיה הערך של האם המשבצת ריקה
SW.WriteLine(bord[i, j].GetIsEmpty().ToString());
//-------------------------------------------------
SW.WriteLine("Type"); // סוג החייל, אם אין חייל בכל השורות אשר מתקשרות לחייל יהיה רשום 0
if (bord[i, j].GetIsEmpty())
SW.WriteLine("0");
else
SW.WriteLine(bord[i, j].GetPiece().Gettype());
//------------------------------------------------
SW.WriteLine("Path");// הכתובת של השתמונה של החייל
if (bord[i, j].GetIsEmpty())
SW.WriteLine("0");
else
SW.WriteLine(bord[i, j].GetPiece().GetPath());
//-------------------------------------------------
SW.WriteLine("First"); // האם התזוזה הראשונה
if (bord[i, j].GetIsEmpty())
SW.WriteLine("0");
else
SW.WriteLine(bord[i, j].GetPiece().Getfirst().ToString());
//-----------------------------------------------------------
SW.WriteLine("Color"); // צבע החייל, כלומר איזה צד- שחורים או לבנים
if (bord[i, j].GetIsEmpty())
SW.WriteLine("0");
else
**
if (bord[i, j].GetPiece().GetWhite())
SW.WriteLine("White");
else
SW.WriteLine("Black");
}
//---------------------------------------
SW.WriteLine("From_i"); // האינדקס של המקום האחרון שהחייל שנמצא על המשבצת היה בו, אם אין חייל יהיה 0
if (bord[i, j].GetIsEmpty())
SW.WriteLine("0");
else
SW.WriteLine(bord[i, j].GetFrom().X.ToString());
SW.WriteLine("From_j"); // האינדקס של המקום האחרון שהחייל שנמצא על המשבצת היה בו, אם אין חייל יהיה 0
if (bord[i, j].GetIsEmpty())
SW.WriteLine("0");
else
SW.WriteLine(bord[i, j].GetFrom().Y.ToString());
//----------------------------------------------------
SW.WriteLine("End"); //סימון שהמשבצת הראשונה הסתיימה ומעבר למשבצת הבאה
}
}
SW.Close();
i tried giving premmisions to everyone in that folder, didnt work, plz help me, i need to start getting close to finishing this project or i wont get a grade on it. thanks. Last edited by Meydanb; 05-31-2009 at 07:34 AM. |
|
|
|
|
| Important Information |
|
Join the #1 Tech Support Forum Today - It's Totally Free!
TechSupportForum.com is a leading support website for your computer needs. We offer free, friendly and personalized computer support. Why pay to have your computer fixed when you can do it for free. Join TechSupportforum.com Today - Click Here |
|
|
#2 (permalink) |
|
Design Team Member
Join Date: Jul 2007
Location: Coventry, UK
Posts: 1,854
OS: Vista, various linux distros
|
Re: C# Error while trying to create text file
Hey, have you checked the file exists//is created by the program? Basically you need to narrow down the error to a specific function call. If you can't do that then i suggest you go about changing your script to include the File.exists function to check that it exists, then that you can open it, etc. (Examples here: http://msdn.microsoft.com/en-us/libr....readline.aspx)...
Also are you running this straight from your IDE? It could be a local permissions problem because of that, run it from the command line (making sure it's your user's session). Cheers, Jamey |
|
|
|
|
|
#3 (permalink) |
|
Registered User
Join Date: May 2008
Posts: 6
OS: winXP SP2 (switching to linux)
|
Re: C# Error while trying to create text file
well i found what was causing the error, the problem was that i forgot to add the name of the file and ".txt" so that was the problem...
by the way this is the code that creats the file so i dosnt exists until this code is executed... so thnx anyway... Last edited by Meydanb; 06-01-2009 at 01:03 AM. |
|
|
|
|
|
#4 (permalink) |
|
Design Team Member
Join Date: Jul 2007
Location: Coventry, UK
Posts: 1,854
OS: Vista, various linux distros
|
Re: C# Error while trying to create text file
Haaha, ohhh, so you were trying to hardwrite directly to the directory? i thought saves was just the name of an empty file. Glad you've got it sorted.
|
|
|
|
![]() |
| Thread Tools | |
|
|