locked
Upload document in document library which has unique permissions RRS feed

  • Question

  • Hi All,

    I have one Document library which has unique permissions and trying to upload document with SPList server object model getting error.

    I wand to upload document in document library which has unique permissions. How to achieve this?

    Thanks,

    Harish Patil

    Friday, July 10, 2020 9:55 AM

Answers

  • Hi

    By using server object model, what error did you meet?


    Justin Liu Office Apps & Services MVP, MCSE
    Senior Software Engineer
    Learn Microsoft 365 from Microsoft DOCs now!
    Please Vote and Mark as Answer if it helps you.

    • Marked as answer by WOW 999999 Friday, July 17, 2020 4:22 PM
    Monday, July 13, 2020 12:57 AM
  • Hello Harish Patil,

    What's the error did you get? Please share your code and details about the error so I could  help you better.

    Besides, below is my sample code to upload document in document library:

    using (SPSite site=new SPSite("http://sp2016/sites/dev"))
          {
            SPWeb web = site.OpenWeb();        
            SPFolder library = web.Folders["doc02"];
            FileStream fileStream = File.OpenRead(@"C:\Test.txt");
            string filename = "Test.txt";
            SPFile file = library.Files.Add(filename, fileStream);
            library.Update();
          }

    Best Regards,

    Michael Han


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Monday, July 13, 2020 5:42 AM

All replies

  • Hi

    By using server object model, what error did you meet?


    Justin Liu Office Apps & Services MVP, MCSE
    Senior Software Engineer
    Learn Microsoft 365 from Microsoft DOCs now!
    Please Vote and Mark as Answer if it helps you.

    • Marked as answer by WOW 999999 Friday, July 17, 2020 4:22 PM
    Monday, July 13, 2020 12:57 AM
  • Hello Harish Patil,

    What's the error did you get? Please share your code and details about the error so I could  help you better.

    Besides, below is my sample code to upload document in document library:

    using (SPSite site=new SPSite("http://sp2016/sites/dev"))
          {
            SPWeb web = site.OpenWeb();        
            SPFolder library = web.Folders["doc02"];
            FileStream fileStream = File.OpenRead(@"C:\Test.txt");
            string filename = "Test.txt";
            SPFile file = library.Files.Add(filename, fileStream);
            library.Update();
          }

    Best Regards,

    Michael Han


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Monday, July 13, 2020 5:42 AM
  • Hello Harish Patil,

    Is there anything update?

    Please remember to mark the reply as an answer if it helps you.

    Best Regards,

    Michael Han


    "SharePoint" forums will be migrating to a new home on Microsoft Q&A !
    We invite you to post new questions in the "SharePoint" forums' new home on Microsoft Q&A !

    Friday, July 17, 2020 7:28 AM
  • Thanks Michael and Justin. Issue is resolved.
    Friday, July 17, 2020 4:21 PM