Showing posts with label sharePoint 2013. Show all posts
Showing posts with label sharePoint 2013. Show all posts

Tuesday, April 25, 2017

How to limited number of Rows in return in Data Loading with SharePoint CSOM?

when we load list item from a large document library, the process will hang due to large volumn of items.

it is quite easy to improve the performance to limited the number of rows return from the query. we just need to set the ViewXml property from teh CamlQuery object.

limitedQuery.ViewXml = "<View><RowLimit>50</RowLimit></View>";


 class Program
    {
        static void Main(string[] args)
        {

            string siteUrl = "http://SharepointSever";

            SP.ClientContext clientContext = new SP.ClientContext(siteUrl);

            SP.List oList = clientContext.Web.Lists.GetByTitle("My Documents");
            SP.CamlQuery limitedQuery = new SP.CamlQuery();
            limitedQuery.ViewXml = "<View><RowLimit>50</RowLimit></View>";

            SP.ListItemCollection collListItem = oList.GetItems(limitedQuery);

            clientContext.Load(collListItem);

            clientContext.ExecuteQuery();

            foreach (SP.ListItem oListItem in collListItem)
            {
                Console.WriteLine("ID: {0} \nTitle: {1}", oListItem.Id, oListItem["Title"]);
            }
            Console.ReadLine();

        }
    }

Monday, November 23, 2015

How to fix the navigation issue in SharePoint MVC app.

when we select a MVC project template in the visual studio, it automatically generate the page navigation in the layout page. the following snipet of code will show you the systematically generated code

 <li>@Html.ActionLink("Home", "Index", "Home", null)</li>

in the Sharepoint MVC app implement, if we use the same code as above. when we click on the hyper link.
we will use this error message.



 when we exam the web url.

http://localhost/MySPMVCAppWeb/?Length=4. the SPHostUrl is missing in the url. which is root cause of the above issue.

we simply add SPHostUrl Parameter before the null parameter, will help us solve the above issue and allow user to navigate all pages with the app.

<li>@Html.ActionLink("Home", "Index", "Home", new { SPHostUrl = SharePointContext.GetSPHostUrl(HttpContext.Current.Request).AbsoluteUri }, null)</li>









Wednesday, August 26, 2015

How to fix the Sharepoint Provider Host App deployment Issue after create a new branch on TFS (Team Foundation Server)

After I deploy the Sharepoint Provider App to the Production Server, then I branch out a new project on the current project for continuing development.

Howerver, i deploy the app to the Sharepoint Development Server, I try to access the item in document library. I always encounter this error

clientContext.ExecuteQuery(); Access denied. You do not have permission to perform this action or access this resource.

The cause of this issue is that App still use the previous clientID, which is reference to the Previous App Web.


We should generate a new Client ID for the new branch

use the new GUID to replace the clientId in appManifest.xml of Sharepoint App Project.

 <AppPrincipal>
    <RemoteWebApplication ClientId="9bb877e4-1c73-4258-8224-924c2e75a8f0" />
  </AppPrincipal>

replace the previous clientId with new Guid ID in the web.config File in the App Web Project.

  <add key="ClientId" value="9bb877e4-1c73-4258-8224-924c2e75a8f0" />


Thursday, June 18, 2015

Helpful tips on create a SharePoint 2013 Virtual Machine with Windows Server 2012 R2 with Update

1. How to solve AppFabric Server installation error.

you can resolve by modifying the PSModulePath environment variable manually in Control Panel->System->Advanced System Settings->Advanced tab->Environment Variables->system variables. then remove the double quotation.

2. How to fix Application Server Role, Web Server(IIS) Role Configruation error.

go to windows\system32 directory.
then just make duplication for the servermanager.exe and then rename to servermanagercmd.exe

Wednesday, April 15, 2015

How to Retrieve Host Url Query String from sharepoint App?

I encounter a challenge issue today. My manager want to have a new feature in the current testing sharepoint app. he want the current app can show the record detail. It means that the app will expect a dynamic detail record ID.

Since the app had been inserted into the host page, display the content within the host page iframe section.

here is the url that the use will use to access the record detail

https://<<SharepointWebSite>>/Forms/Pages/MyHostPage.aspx?QueryID1=Value1&QueryID2=Value2&Value3=24833

After I google the web, the MSDN article provide a great help on solving this challenge task.

https://msdn.microsoft.com/en-us/library/office/fp179921.aspx


Step 1. Add New custom properties to the Properties Section in the Elements.xml file for the ClientWebPart.

<Properties>
      <Property Name="QueryID1" Type="string" DefaultValue="QueryID1Value" WebBrowsable="true" WebDisplayName="DealerID" WebDescription="" WebCategory="Basic app part category" RequiresDesignerPermission="true">
       
      </Property>
      <Property Name="QueryID2" Type="string" DefaultValue="QueryID2Value" WebBrowsable="true" WebDisplayName="DealerID" WebDescription="" WebCategory="Basic app part category" RequiresDesignerPermission="true">

      </Property>
      <Property Name="QueryID2" Type="string" DefaultValue="QueryID3Value" WebBrowsable="true" WebDisplayName="DealerID" WebDescription="" WebCategory="Basic app part category" RequiresDesignerPermission="true">
      </Property>
    </Properties>


Step 2. change the Content Type Src attribute by appending the new query string to the end in the Elements.xml file for the ClientWebPart.

 <Content Type="html" Src="~remoteAppUrl/Pages/Default.aspx?{StandardTokens}&amp;QueryID1=_QueryID1_&ampQueryID2=_QueryID2_&amp;QueryID3=_QueryID3_" />

Step 3. Create a JavaScript file to grab the host url query string value and use them to replace those property default value in the  path source of content type.

after the deployment, the embedded app will contains the following QueryString with default value replaced _QueryStringName_  in its url

&QueryID1=QueryID1Value&QueryID2=QueryID2Value&QueryID3=QueryID3Value&SenderId=MyID002

<script>
var arrFrames = document.getElementsByTagName("iframe");
for(i = 0; i< arrFrames.length; i++)
{
    var iFrame=arrFrames[i];
    var QueryID1="QueryID1Value";
    if(iFrame.src.indexOf(QueryID1) != -1)
    {
        var QueryID1Value=getQuerystring("QueryID1");
        if (QueryID1Value != null)
        {
            iFrame.src=iFrame.src.replace(QueryID1,QueryID1Value);
        }
    }
    var QueryID2="QueryID2Value";
    if(iFrame.src.indexOf(QueryID2) != -1)
    {
        var QueryID2Value=getQuerystring("QueryID2");
        if (QueryID2Value != null)
        {
            iFrame.src=iFrame.src.replace(QueryID2,QueryID2Value);
        }
    }
    var QueryID3="QueryID3Value";
    if(iFrame.src.indexOf(QueryID3) != -1)
    {
        var QueryID3Value=getQuerystring("QueryID3");
        if (QueryID3Value != null)
        {
            iFrame.src=iFrame.src.replace(QueryID3,QueryID3Value);
        }
    }
}

function getQuerystring(key)

{
    key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
    var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
    var qs = regex.exec(window.location.href);
    if(qs == null)
        return null;
    else
        return qs[1];
}

</script>


Step 4. Deployment the modified Sharepoint App with new Version Number, so the update process can overwrite the existing app.


Step 5. Add javascript code and SharePoint app to the host page. 

 first, we must add the Script Editor Web Parts from Media and Content Categories to the host page, so that the embedded script will render to replace those default query value after the app part had been rendered




 then click on the Edit Snippet Button to open the Embed Script Editor, then copy and paste the above script to the editor, click Insert to complete the process.



 
second, we will added the app part to the host page, which stays on the top of the Script Editor Web Part.

Now the SharePoint app will able to grab the host web page query string and render them within itself.