Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I am trying to make a program which can convert a table out of a sdf file into a csv file. But somehow i cant create a csv file because it is denied. Please ignore the comments..
C#
private void button2_Click(object sender, EventArgs e)
        {
            
            SqlCeConnection conn = null;
            SqlCeCommand cmd = null;
            SqlCeDataReader rdr = null;


            try
            { 
                <code>System.IO.TextWriter stm = new System.IO.StreamWriter(new System.IO.FileStream(@"C:\Users\Name\Desktop\...\...\Columba\Columba-XT-Standard-20180710155851", System.IO.FileMode.Create), Encoding.Default)</code>;
                while (rdr.Read())
                {
                    for (int i = 0; i < rdr.FieldCount - 2; i++)
                    {
                        if (rdr[i] != null)
                        {
                            stm.Write(rdr[i].ToString());
                            stm.Write(";");
                        }
                        else
                        {
                            stm.Write(";");
                        }
                    }
                    if (rdr[rdr.FieldCount - 1] != null)
                    {
                        stm.Write(rdr[0].ToString());
                    }
                    stm.Write(System.Environment.NewLine);
                }
                stm.Close();

                rdr.Close();

                cmd.Dispose();
            }
            finally
            {
                conn.Close();
            }
            
            
        }


What I have tried:

I tried to make a folder on the D, but i did not work.
Then i tried to start vs with admin rights...
Posted
Updated 19-Jul-18 1:54am
v4
Comments
CHill60 19-Jul-18 5:51am    
If access is denied then either you don't have access (but the administrator mode should have sorted that) OR possibly you are not writing where you think you are and that is a system folder - your folder name does not look correct Desktop\...\...\Columba - where do think that is going? Users\Name\ - you have a user id of "Name"?
Try putting in the full path to the file and see if that helps.
Also make sure that nothing else has a previous copy of the CSV open
Member 13917889 19-Jul-18 7:22am    
thank you i solved the problem!
CHill60 19-Jul-18 7:49am    
Was it the ... in the path or the Name ... or both?
Richard MacCutchan 19-Jul-18 6:38am    
Your pathname is not valid: you cannot have folders named "...".
Member 13917889 19-Jul-18 7:50am    
i forgot to giva it a filename.. :)

1 solution

Forgot to name the file...

C#
System.IO.TextWriter stm = new System.IO.StreamWriter(new System.IO.FileStream(@"D:\\TEST\<code>Data.csv</code>", System.IO.FileMode.Create), Encoding.Default);
 
Share this answer
 
v2

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