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);
            }
        }
3
  • 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, 2015 at 19:49
  • 1
    You don't have access to file system from Sandboxed Solution. It is blocked, hence sandboxed
    – eirikb
    Feb 19, 2015 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, 2015 at 19:51

1 Answer 1

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 and acknowledge that you have read and understand our privacy policy and code of conduct.

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