locked
Access to the file from SharePoint RRS feed

  • Question

  • Hi everyone. I need some help with getting data from the *.txt-file.
    My WebPart has one Label and I want to fill it with data from my file.
    lbl.Text = File.ReadAllText(WebConfigurationManager.AppSettings["DataFile"]);
    I set trust level in my web.config:
    <trust level="WSS_Medium" originUrl="" />
    Also my web.config contains path to the file with data:
    <connectionStrings>
        <add name="DataFile" connectionString="C:\Users\admin\Documents\test.txt"/>
      </connectionStrings>
    
    When I try to display my WebPart I have following message:
    "An unexpected error has occurred.
    Web Parts Maintenance Page: If you have permission, you can use this page to temporarily close Web Parts or remove personal settings. For more information, contact your site administrator.
    Troubleshoot issues with Windows SharePoint Services. "


    When I did the same on SP 2010 it did work. But now I have got the same task to do on SP WSS 3.0.

    I'm completely confused. What can be wrong?

     



    • Edited by Vityusha Monday, November 21, 2011 10:06 AM
    Monday, November 21, 2011 10:04 AM

Answers

  • I think you'll need full trust to access anything in the file system outside of inetpub.

    An easier option if you can do it would be to just upload the text file into SharePoint somewhere, there should be no access issues then.

    Monday, November 21, 2011 2:12 PM

All replies

  • Try to run your code under runwithelevatedprivileges block.
    Thanks, Amit Kumar, LinkedIn Profile ** My Blog
    Monday, November 21, 2011 11:35 AM
  • I've tried but it doesn't work.

    I have System.Security.SecurityException without InnerException.

    Monday, November 21, 2011 12:20 PM
  • Try to provide admin rights to "System User" (under which runwithelevatedprivileges code run) in the folder where .txt file exist.

    Thanks, Amit Kumar, LinkedIn Profile ** My Blog
    Monday, November 21, 2011 12:32 PM
  • I've added full rights for everyone, but it still doesn't work (
    Monday, November 21, 2011 1:39 PM
  • I think you'll need full trust to access anything in the file system outside of inetpub.

    An easier option if you can do it would be to just upload the text file into SharePoint somewhere, there should be no access issues then.

    Monday, November 21, 2011 2:12 PM
  • Full trust works! Thank you.

    I'm interested how can I get access to the internal uploaded file?

    Could you please write some lines of code?

    Monday, November 21, 2011 2:54 PM
  • You can see the following article for more information about how to update files to SharePoint libraries from local folder:
    http://msdn.microsoft.com/en-us/library/ms454491.aspx


    Jinchun Chen
    Forum Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact tnmff AT microsoft.com(Please replace AT with @)
    Monday, December 5, 2011 3:07 AM
    Moderator