Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5848275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:50:11+00:00 2026-05-22T12:50:11+00:00

i’m developing an interface to retrieve a file from sharepoint. i have the following

  • 0

i’m developing an interface to retrieve a file from sharepoint. i have the following method to upload a document:

    public bool UploadDocument(string document)
    {
        if (String.IsNullOrEmpty(Path.GetFullPath(document)))
        {
            return false;
        }

        var site = GetNewDataContext(SiteUrl);
        try
        {
            using (var clientContext = GetNewContext())
            {
                var uploadLocation = string.Format("{0}{1}/{2}", SiteUrl, Helpers.ListNames.RequestedDocuments, Path.GetFileName(document));

                //Get Document List
                var documentslist = clientContext.Web.Lists.GetByTitle(Helpers.ListNames.RequestedDocuments);

                var fileCreationInformation = new FileCreationInformation
                {
                    Content = System.IO.File.ReadAllBytes(document), //Assign to content byte[] i.e. documentStream
                    Overwrite = true, //Allow owerwrite of document
                    Url = uploadLocation //Upload URL
                };

                var uploadFile = documentslist.RootFolder.Files.Add(fileCreationInformation);

                uploadFile.ListItemAllFields.Update();

                clientContext.ExecuteQuery();
            }
            site.SubmitChanges(ConflictMode.FailOnFirstConflict, true);
        }
        catch (Exception exception)
        {
            throw new ApplicationException(exception.Message);
        }

        return true;
    }

However, my next step is to apply a custom permission.. i’ve found some blogs online which demonstrate how to do this:
http://howtosharepoint.blogspot.com/2010/10/programmatically-add-delete-modify-item.html

  • Is it possible to set the permission in the uploading process?
  • my understanding is, when the file is uploaded it inherits permissions from the list its uploaded to.
  • my current download method returns a ListItem.. Is it possible to cast a ListItem to SPListItem? The reason for returning a SpListItem is due to the blog i posted above.. it appears SPListItem contains the permission info i need [to break and apply the new permission to].

my download method returns a ListItem.. how can i do this as an SPListItem

    private static ListItemCollection GetListItemCollectionFromSp(string documentListName, string name, string value, string type, int rowLimit)
    {
        ListItemCollection listItems = null;
        using (var ctx = GetNewContext())
        {
            var documentsList = ctx.Web.Lists.GetByTitle(documentListName);

            var camlQuery = new CamlQuery
            {
                ViewXml =
                    @"<View>

                    <Query>
                        <Where>

                            <Eq>
                                <FieldRef Name='" + name + @"'/>

                                <Value Type='" + type + "'>" + value + @"</Value>
                            </Eq>

                        </Where>
                        <RowLimit>" + rowLimit + @"</RowLimit>

                    </Query>
                </View>"
            };

            listItems = documentsList.GetItems(camlQuery);

            ctx.Load(documentsList);

            ctx.Load(listItems,
                items => items.IncludeWithDefaultProperties(
                item => item.DisplayName));

            ctx.ExecuteQuery();
        }

        return listItems;
    }

thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T12:50:12+00:00Added an answer on May 22, 2026 at 12:50 pm

    Looks like you are trying to configure item level permissions in document library. Correct me if I am wrong.

    Firstly, You have to stop inheriting permissions from parent site. You can then create a workflow and let it trigger when a document is uploaded. It is easy to design a workflow to configure permissions on item level than doing it in code. Maintenance would be easy too.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have a bunch of posts stored in text files formatted in yaml/textile (from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.