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

Monday, April 27, 2015

SharePoint – Back to basics – SPLongOperation for lengthy operations

We have many hidden features in SharePoint in look and feel in Out of Box as well as custom. SPLongOperation One of the hidden feature in custom coding side. This feature exists from SharePoint but many of the users may not be aware of this. SPLongOpearation allows us to inform end users on processing screen while operating lengthy operations like moving documents from one site other, deleting sites etc... And at the end we can have options to close/ redirect the page.

Here is the sample code on usage of SPLongOperation,

               try{
                              using (SPLongOperation longOpearation = new SPLongOperation(this.Page))
                              {
                                             longOpearation.LeadingHTML = "Title of the long operation";//title message
                                             longOpearation.TrailingHTML = "this will take few sec”//sub message
                                              longOpearation.Begin();
                                             //Code start
                                             //Write the code that to be processed in long operation
                                             //code ends
                                               HttpContext context = HttpContext.Current;
                                             if (context.Request.QueryString["IsDlg"] != null)
                                             {
                                                            context.Response.Write("<script type='text/javascript'>window.frameElement.commitPopup();</script>");
                                                            context.Response.Flush();
                                                            context.Response.End();
                                              }
                                              else
                                              {
                                                             string url = SPContext.Current.Web.Url;
 longOpearation.End(url, SPRedirectFlags.CheckUrl, context, string.Empty);
                                             }

                              }
               }
               catch (Exception ex)
              {
                              SPUtility.TransferToErrorPage(ex.ToString());//transfores us to the error page with error message
               }

In the Begin and End methods for long operation we can have different overloaded methods. By using SPLongOperation.Begin method (String, String, SPLongOperation.BeginOperation) method we can pass title and sub message. Here in the script end method, iam passing redirection URL and checking flags and current context. For more details, here is the full description in msdn.



Sunday, April 26, 2015

SharePoint error – A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible.

While working on one of the existing SharePoint server, I tried to open the SharePoint central admin site. I got an error saying that “A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible.” As shown the image below.



This is the error due to SQL server service got stopped. To fix the error we have to run the SQL Service as shown the image below.



But in my case, MSSQLSERVER service is started and running. Restarted the service, but it wasn’t worked for me. By digging in to the deep I got few details from system admin. The farm I am working is already had few sites. But before handing that to me all the sites deleted from SQL server. When I try to access the CA site it gives the error message.

Restarted SharePoint timer service, SQL server and all the servers in the farm. Nothing worked for me. Finally ran SharePoint configuration wizard. Super... it worked for me. Now I got the issue that some of my farm users deleted DB’s in sql server directly instead deleting form CA. By running the config wizard


Friday, April 3, 2015

SharePoint 2013 - Update master page styles in SharePoint hosted apps without coding

One of my project I got a requirement to remove top suite links in a SharePoint hosted master page. But app was not developed by us. It is third party app. We don’t have code for the app. We just got app file and configured it in app site collection.

But one of management asked us to remove top suite links (Sites, One Drive and Newsfeed). We need to update the app master page links. I have worked on app, but all did form code side. But we don’t have code access now.


Generally we can have options to see site settings and all site contents of the app web by navigating to http://appweburl/_layouts/settings.aspx, http://appweburl/_layouts/viewlsts.aspx ). But in our app, app developers restricted to view those pages. I have tried to edit the app page as it is general SharePoint page. But I am unable to edit the page.

Finally a simple trick worked for me. Navigated to master page gallery http://appweburl/_catalogs/masterpage. Yes, I have access to master page gallery. In master page gallery I have seen all master pages related to SharePoint 2013 (app.master, seattle.master, oslo.master..etc.) By default app web use app.master page. Download app.master to your local and add CSS/JavaScript code to the master page. Upload it to masterpage gallery again.



In my case I just made added #DeltaSuiteLinks{display:none} style in the master page. It worked for me. But make sure check this before in Dev/Stage before updating the production.


Hope this helps.

Saturday, March 21, 2015

Exception from hresult 0x800a03ec excel - Error ‘Microsoft Office Excel cannot access the file’ while accessing Microsoft Office 11.0 Object Library

We got this error with SharePoint 2007 farm custom coding. Code downloads all the list items to excel template. Generally we can see this error with rows updating in excel. But we haven’t changed anything from DEV to PROD. We have investigated the error in SharePoint logs and Event logs.
We are seeing the error as there are several possible reasons: 
·           The file name or path does not exist.
·           The file is being used by another program.
·           The workbook you are trying to save has the same name as a currently open workbook.
After checking the issue. We have found that there is the error with excel service. To fix that we have to create a folder.

If we are running in Windows Server 2008 64-bit/R2,
·           Navigate to C:\Windows\SysWOW64\config\systemprofile folder and create the following directory “Desktop”
If we are running in Windows Server 32-bit
·           Navigate to C:\Windows\System32\config\systemprofile\Desktop folder and create the following directory “Desktop”

If still you have the issue, you have to change the security setting to run excel application using following steps,

·           Start –> enter DCOMCNFG.exe to open Component Service
·           This will bring up the component services window, expand out "Console Root" -> "Computers" -> "DCOM Config"
·           Find "Microsoft Excel Application" in the list of components.
·           Right click on the entry and select "Properties"
·           Go to the "Identity" tab on the properties dialog.
·           Select "The interactive user."
·           Click the "OK" button.
·           Switch to the services console
·           Start the service automating Excel
·           Test you application again.


Enable Windows authentication in IIS if excel application in your site prompting for credentials.

Saturday, March 14, 2015

Get all the site collection with content DB details using powershell commands

As discussed earlier power shell commands are pretty powerful than SharePoint object model code. Some time we can't run SharePoint object model code in production environment like gathering site/server/DB details.

We can get sites and content DB details using following power shell commands 


$rootSite=New-Object Microsoft.SharePoint.SPSite("Web app URL")
$spWebApp = $rootSite.WebApplication 
foreach($site in $spWebApp.Sites) {
    
    write-output "$($site.RootWeb.Url) - $($site.ContentDatabase)"     
  
    $site.Dispose() 


Wednesday, March 11, 2015

Create explicit managed path for host named site collection using PowerShell commands

In SharePoint 2013, host-named site collections (HNSC) are all the rage. Host-named site collections give you the ability to provide completely different URLs for a site collection regardless of the web application URL hosting it.  For example, you might have a web application URL named http://sharepoint.mycompany.com and under it you have a collaboration site with a URL of http://collaborate.mycompany.com and an Intranet site namedhttp://intranet.mycompany.com.  This allows you to host multiple types of SharePoint sites together on a single web application which ultimately reduces the amount of resources your server farm needs for application pools.

Just like any site collection, you have to create a managed path for the URL you want.  We do this using New-SPManagedPath.  We can add explicit or wildcard inclusions just like you can for path-based site collections.  Wildcard is the default, if you want explicit, include the –explicit parameter.  We also need to add the –HostHeader parameter to indicate this is used with host-named site collections.  Here’s an example, where I created the business-solutions explicit path from our example above.

New-SPManagedPath "managed path name" -HostHeader –Explicit

This technically makes this managed path available on any host-named site collection.  If you want to see what managed paths have been created for host-named site collections, use Get-SPManagedPath with the –HostHeader command.

Get-SPManagedPath –HostHeader

Now, we need to create the site collection using New-SPSite.  It takes a few parameters but the important ones for this scenario is the URL we want for the new site collection and then –HostHeaderWebApplication to specify which web application hosts the new site collection.

New-SPSite “Site collection URL” –HostHeaderWebApplication “host web app URL” -Name "Site collection name" -OwnerAlias domain\user  -Template STS#0