Problem in create file

Hi,

I am trying to use this code in order to create file in specific path (resultsDestination) :

string resultsDestination = Environment.ExternalStorageDirectory + "/FFS/Results/" +
subjectAdapter [CoursesList.CheckedItemPosition] + "/" +
quizzesNames [TypeTest.CheckedItemPosition] + ".txt";

            using (var fileStream = System.IO.File.Open (resultsDestination, System.IO.FileMode.Create, System.IO.FileAccess.Write))
            {
                // Do something
            }

But, it's causes application to crash.
Why ?

Thanks.

Answers

  • YkshLeoYkshLeo USMember ✭✭✭✭

    Check your Diagnostic build output to know the real exception or error which leads to application crash.

  • ConorMurphyConorMurphy USMember ✭✭

    I'm not sure what your crash is without seeing the exception/error but i create a file in a destination via this code:

        private void CreateNewFile (){
            string path = /*String of the path you want to create*/
            System.IO.Directory.CreateDirectory (path); //Creates the path directory
            AppendRecordFile (path + "/" + "FileName" + ".TXT");  //Pass the file name you want;
        }
    
        private void AppendFileToDirectory(string fileName){
            using (var streamWriter = new StreamWriter(fileName, true)) 
            {
                streamWriter.WriteLine("John Doe");
                streamWriter.Close ();
            }
        }
    

    Hopefully this help.

Sign In or Register to comment.