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:
* Get free support
* Communicate privately with other members (PM).
* Removal of this message
* 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
Go Back   Tech Support Forum > The IT Pro > Programming
User Name
Password
Site Map Register Donate Rules Blogs Mark Forums Read


Programming A discussion forum for programs and programming used in tech-related businesses.

Reply
 
LinkBack Thread Tools
Old 05-31-2009, 07:33 AM   #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:
Access to the path 'D:\Projects\Meydan\Chess\Saves' is denied.
this is the code:
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();
sorry for the comments in jibrish, its hebrew so youl probably wont understand them.

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.
Meydanb is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
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

Old 05-31-2009, 05:16 PM   #2 (permalink)
Design Team Member
 
jamiemac2005's Avatar
 
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
__________________

Myspace
jamiemac2005 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 06-01-2009, 01:01 AM   #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.
Meydanb is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 06-01-2009, 04:06 AM   #4 (permalink)
Design Team Member
 
jamiemac2005's Avatar
 
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.
__________________

Myspace
jamiemac2005 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 06-01-2009, 04:33 AM   #5 (permalink)
Registered User
 
Join Date: May 2008
Posts: 6
OS: winXP SP2 (switching to linux)


Re: C# Error while trying to create text file

yep...
thnks for your help anyway.
Meydanb is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -7. The time now is 10:10 AM.



Copyright 2001 - 2009, Tech Support Forum
Home Tips Plus | Outdoor Basecamp | Automotive Support Forum

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85