0

I'm using a sandboxed solution, this is the error I got when I try to make the txt

Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed. sharepoint

This is the code I have for creating and writting on the file

string path = @"C:\pruebas\" + txtNombre.Text + ".txt";
        if (!File.Exists(path))
        {
            using (StreamWriter sw = File.CreateText(path))//here happens the error
            {
                sw.WriteLine("Hello");
                sw.WriteLine(Texto);
            }
        }
        using (StreamReader sr = File.OpenText(path))
        {
            string s = "";
            while ((s = sr.ReadLine()) != null)
            {
                Console.WriteLine(s);
            }
        }
  • try without the @, which using means a literal string. Try to spit out the path variable to make sure it is valid. – Mike Feb 19 '15 at 19:49
  • 1
    You don't have access to file system from Sandboxed Solution. It is blocked, hence sandboxed – eirikb Feb 19 '15 at 19:50
  • I made it a farm solution, and works now, but the problem is that the .txt file is created on the server and not on the user pc – Uhcnamuf Feb 19 '15 at 19:51
0

If you need full trust operations in sandboxed code, you can create and use sandbox proxies, as described here, here and here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.