none
How to create new file *.txt in c:/

    Question

  • Hello! I read several post about to create/open files in silverlight aplication. My problem is: I have a silverlight web part that displays a datagrid. My aim is to export a *.txt or excel file. I need that file is created in the directory main "c", so use the IsolatedStorageFile class i think don't help me. I have been testing with the nex code: FileStream fs = new System.IO.FileStream(@"C:/DataGridViewData.txt", FileMode.Create, FileAccess.Write); string strCadena=string.Empty; StreamWriter m_streamWriter = new StreamWriter(fs); m_streamWriter.BaseStream.Seek(0, SeekOrigin.End); m_streamWriter.Write(strCadena + "\n"); ¿Any idea? Thanks a lot. Greetings
    Monday, May 17, 2010 6:11 AM

Answers

All replies

  • Sorry you wil not be able to save a file in c:\. 

    Monday, May 17, 2010 6:16 AM
  • Thank you!
    Monday, May 17, 2010 6:32 AM
  • Use the other drives to save the file as there is some security reason by which you can nopt save the file in c:

    Monday, May 17, 2010 7:07 AM
  •  Unfortunately the only way you can access that would be to pop up a SaveFileDialog and have the user select a location. The Silverlight security model makes it impossible (there may be exceptions) to access a specific file location from code, except within the isolated storage location. However, using OpenFileDialogs and SaveFileDialogs allows access anywhere on the system--it's considered "safe" because the user is in total control--but that requires user interaction.

     You can do something like this:

    SaveFileDialog d = new SaveFileDialog();
    
    if (d.ShowDialog().Value)
    {
       System.IO.Stream s = d.OpenFile();
       // Your save file code here.
    }
      

    Then you have a FileStream object that you can deal with as you tried before. This is an extra step, but it should allow the user to save the file any location they like.

    Monday, May 17, 2010 10:54 AM