Upload sharepont Video programmatically

       namespace ConsoleApplication3
       class Program
       static void Main(string[] args)
        using (var site = new SPSite("http://contoso/sites/teams"))
            using (var web = site.OpenWeb())
                  var list = web.Lists.TryGetList("Videos");
                  var videoProperties = new Dictionary<string, object>();
                  videoProperties["Keywords"] = "Intranet Video";
                  //videoProperties["AlternateThumbnailUrl"]   = "/_layouts/images/preview.jpg";
                  UploadVideo(list, @"C:DownloadsVideo3.mp4", videoProperties);

                    public static void UploadVideo(SPList list,string      fileName,IDict   ionary<string,object> properties)
          SPFile file;
          using (var fileStream = File.OpenRead(fileName))
           var urlOfFile = SPUrlUtility.CombineUrl(list.RootFolder.ServerRelativeUrl, Path.GetFileName(fileName));
        file = list.RootFolder.Files.Add(urlOfFile, fileStream, true);
    //listid = list.ID.add();
       SPListItem listItem = list.GetItemById(file.ListItemAllFields.ID);
    //SPListItem listItem = list.GetItems("Video3");

            var videoContentType = list.ParentWeb.Site.RootWeb.AvailableContentTypes["Video"];
       // listItem["ContentTypeId"] = videoContentType.Id;

          foreach (var property in properties)
        listItem[property.Key] = property.Value;

in this code “SPListItem listItem = list.GetItemById(file.ListItemAllFields.ID);
” im getting null reference exception.an i have tried with other line “var listItem = file.ListItemAllFields;”
same error.any one help me to get solve this issue.

What the RESTFul API for GetList of Site

I am looking for the SharePoint OnLine RESTFul API try to get all lists of specified Site.

Let’s say the default Site of Site Collection in my Office 365 SharePoint OnLine trial.
The Site Collection is https://beyondhard.sharepoint.com/.

I just found a sample code for the managed Server Class Libary for SharePoint 2013.

 using (SPSite site = new SPSite("http://localhost/sites/sitecollection"))
    using (SPWeb web = site.OpenWeb("sitecollection/subsite"))
       string listUrl = "/sites/sitecollection/subsite/Lists/Announcements";
       SPList list = web.GetList(listUrl);
       Console.WriteLine("List URL: {0}", list.RootFolder.ServerRelativeUrl);


Is there any RESTFul for it? If could give me some code sample. It will be nice. Thanks.

Script file file not being loaded through ScriptLink custom action – SharePoint app

I am having trouble with script link custom actions. I am building a SharePoint app, and I successfully added a site-scope custom action pointing to a script file in the Style Library, as I want this particular script to be injected to all the pages of my SharePoint site.

While it works in certain situations, the script link injection breaks without apparent reason under certain conditions. For example, when I arrive on my root web, the script will be injected. But, if I go to a certain link within this web (for example Home or Site Contents), the file that is supposed to be injected will simply not be fetched from the Style Library and therefore never be injected, resulting in an uncaught ReferenceError when I try to call one of the script’s function. The weirdest part is that a page refresh through Ctrl+F5 will fetch the script file without any problem, regardless of the page’s ability to originally fetch the script file when first accessed. It will keep the script until it is accessed through a link again.

I’ve read up on Sharepoint caching, thinking it may be the cause of my problem, but the trouble is that these articles mostly talk about cache-induced errors when updating a file, while I am only trying to access it.

One thing to note is that, due to limitations, I am adding the script link custom action through code. Here’s an example of what this kind of call currently looks like in my app:


customAction.Name = "MyScriptLink";
customAction.Location = "ScriptLink";
customAction.Sequence = 100;
customAction.ScriptSrc = "~SiteCollection/Style Library/MySite/MyScript.js";


Also, I know the custom action itself works, since changing the code I just showed by adding instructions in a ScriptBlock property instead of relying on fetching a file through ScriptSrc works like a charm; the code is executed in every page.

So, what’s going on here ? Why is my script no injected on certain pages ? Why does a refresh on these exact same pages manage to fetch the file without any problem ?

Lookup column in provider hosted app

I am creating provider hosted app which has two lists (VS 2013 my SP is in cloud).

One of the lists has a lookup field from the other list created inside of the app (this works).

I need to add couple more lookup fields which will pull from the library that exists in the same site collection where the app will be created.

It looks that property under type for Lookup (this is in the Properties window for the column in VS)

List (should be location of the list), this is where the problem is

I have Lists/Categories in my case but SP is trying to look under site/APP/Lists/ListName once app is deployed

Is there a way to have Lookup look under site/Lists/ListName?



Delete Office365 users from Provider-Hosted App

Could we remotely Delete Office365 users from Provider-Hosted App programatically with C# ? Any suggestions please.
Thank you in advance.

SharePoint Document Library document delete

Please suggest your solution for the following scenario:

A user deletes the document from document library and an e-mail has to be triggered to the admin notifying the information about the document deleted recently along with the option to ApproveReject. If the Admin approves it, the document stays in Recycle Bin and if Rejected, the document gets restored to the document library.

I came across some articles about ‘event receiver’ which can trigger an e-mail but couldn’t find any coding the recycle bin and deletion. Is there any other workaround to implement the same?

2013 grant read access to authenticated users without having to visit site

I have created an app which uses a people picker. The people picker needs to pickup everyone within the NT AUTHORITYauthenticated users group. So I have added that group to the Members group of the site.

Whilst this works, it ONLY works for authenticated users who have visited the site, those who haven’t do not show up the PP results even though they are members of the NT AUTHORITYauthenticated users group.


Is there a way to ensure that all users have visited the site even when they’ve not?

OK i think we are on to something with Camerons point (thanks) i need to trigger the ensureUser but I’m not 100% sure where this should happen and how much i need to do…do i need to add to the group in code or will ensureUser handle all this for me?

Sharepoint provider hosted app Microsoft.SharePoint.Client.File.OpenBinaryDirect does not work

I am trying to do.


Always get “forbidden” and unauthorized.

However If i use same context and url to do web.getFileByServerRelativeUrl() it works as expected.

That assures me, it should not be context or url issue.

Has anyone encountered this before?

User targeted apps store in SharePoint 2013

My company has one SP 2013 intranet portal that is http://intranet.mycompany.com. Everyone in the company daily visits this site. On this portal i want some SharePoint-Hosted apps which user can use for his day to day work.

We have different departments like HR, Sales, Accounts, Production etc. I need apps store on this Portal where user can see apps from his department only, that means HR people should see only HR related apps likewise.

SharePoint Apps File not Found

When I install apps from the Microsoft App Store, I get the following issue:

Sorry, there was a problem with Artezio SP Picture Library Photo Wall- File Not Found.

How can this be resolved?

Question and Answer is proudly powered by WordPress.
Theme "The Fundamentals of Graphic Design" by Arjuna
Icons by FamFamFam