Friday, December 27, 2013

Invalid characters in SharePoint naming conventions

This article lists the characters that you cannot use in the following names in Microsoft SharePoint:

  • Site names
  • Folder name
  • Server names
  • File names

Site names, subsite names, or site group names

  • You cannot use the following characters anywhere in a site name, in a subsite name, or in a site or Active Directory group name:-
    • Tilde (~)
    • Number sign (#)
    • Percent (%)
    • Ampersand (&)
    • Asterisk (*)
    • Braces ({ })
    • Backslash (\)
    • Colon (:)
    • Angle brackets ([ ])
    • Question mark (?)
    • Slash (/)
    • Plus sign (+)
    • Pipe (|)
    • Quotation mark (“)
  • You cannot start a site name, a subsite name, or a site group name with an underscore (_) character or with the period (.) character.
  • When you create a site name, a subsite name, or a site group name, you cannot use strings that were already used to name managed paths.
  • You cannot use the period character consecutively in the middle of a site name, a subsite name, or a site group name.
  • You cannot use the period character at the end of a site name, a subsite name, or a site group name.

Folder names

  • You cannot use the following characters anywhere in a folder name or a server name:
    • Tilde
    • Number sign
    • Percent
    • Ampersand
    • Asterisk
    • Braces
    • Backslash
    • Colon
    • Angle brackets
    • Question mark
    • Slash
    • Pipe
    • Quotation mark
  • You cannot use the period character consecutively in the middle of a folder name.
  • You cannot use the period character at the end of a folder name.
  • You cannot start a folder name with a period character.

File names

  • You cannot use the following characters anywhere in a file name:
    • Tilde
    • Number sign
    • Percent
    • Ampersand
    • Asterisk
    • Braces
    • Backslash
    • Colon
    • Angle brackets
    • Question mark
    • Slash
    • Pipe
    • Quotation mark
  • You cannot use the period character consecutively in the middle of a file name.
  • You cannot use the period character at the end of a file name.
  • You cannot start a file name by using the period character.
  • In addition, file names and folder names may not end with any of the following strings:
    • .files
    • _files
    • -Dateien
    • _fichiers
    • _bestanden
    • _file
    • _archivos
    • -filer
    • _tiedostot
    • _pliki
    • _soubory
    • _elemei
    • _ficheiros
    • _arquivos
    • _dosyalar
    • _datoteke
    • _fitxers
    • _failid
    • _fails
    • _bylos
    • _fajlovi
    • _fitxategiak

Configure SSL for SharePoint 2013

Access SharePoint site using custom URL

Friday, December 20, 2013

Generate script for ALTER DB column Data for all tables available in DB

Run Below query to generate script:

SELECT
'ALTER TABLE ' + TABLE_NAME + ' ALTER COLUMN Createdby varchar(50) ;' +
'ALTER TABLE ' + TABLE_NAME + ' ALTER COLUMN Updatedby varchar(50) ;' AS Script
FROM INFORMATION_SCHEMA.TABLES

Take care of following items:

  • Above query generate scripts for all the tables which were created in that database, deleted tables are also included in it.
  • If tables contains that field or not it will generate script for that table also. Manually you have to remove that table script to run the generated scripts.
  • CreatedBy and UpdatedBy is the field name of the tables which I want to update.
  • Above query generates script for 2 fields, if you want to increase or decrease you have to update above query as per your requirement. 

Thursday, December 5, 2013

How to change Default Home Page : SharePoint

I frequently get questions on changing the home page or using another page as the home page:

  • Can I have three (or four or five or…) columns in the default home page?

  • Do I have to use the new wiki home page in my Team Site?

  • I want to test a new home page design, but I don’t want to lose the existing home page… (just in case you know…)

  • How can I use a page from my wiki library as my home page?


Below are four ways to set another page as your home page: (all four work for both 2007 and 2010)

  • From Site Settings (If the publishing features are enabled)

  • From SharePoint Designer

  • From code / API

  • From PowerShell


The first two can be used by Site Owners, the second two can only be used for developers and administrators

Important Notes for all methods:
Make sure all of your users have at least read access to the new home page, and if in a library that you have it checked in and published.

1.   If the Publishing features are enabled for a site then: (From Site Settings)


Click on Site Action  =>  Site Setting  =>  Welcome Page

Image

2.   From SharePoint Designer:


Right-click the new page and click "Set as Home Page".  (For SharePoint 2007 this only appears to work from SharePoint                    Designer if the file is in the root of the site. I.e. the same place as default.aspx.)

Image

3. From Code / API


Please follow the following link for code.

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spfolder.welcomepage.aspx

4. Via PowerShell


$site = Get-SPSite http://yourserver/sites/yoursite
$web = $site.RootWeb (or $web = $site.OpenWeb("yoursubsite")
$folder = $web.RootFolder
$folder.WelcomePage = "SitePages/home.aspx"
(or $folder.WelcomePage = "default.aspx")
(or $folder.WelcomePage = "Shared%20Documents/mycustomwebpartpage.aspx")
$folder.update()
$web.Dispose()
$site.Dispose()

If you need any type of help please let me know on following email id : jaydoshi.com@gmail.com. Thank You.

Tuesday, October 8, 2013

How to Close Model Dialog on Button Click

 
<asp:Button Text="Close" runat="server" ID="btnClose"
          OnClientClick="javascript:window.frameElement.commitPopup();" />

Thursday, September 12, 2013

Configure RDLC Report with ReportViewer : SharePoint 2010

I have worked with SharePoint 2010 Foundation and found the RDL(C) report is not configured automatically.  To run a successfully report I applied the following changes in SharePoint web.config file. To make sure the configuration works for reporting just put a reportviewer control inside a webpart/page and try to access the page. First of all make sure you have intalled “Microsoft Report Viewer 2010 Redistributable Package”. You can it from here.

Here I am going to list down steps to configure report viewer setting for SharePoint.

1.   First find the following line in AppSettings and comment it out as shown below:
 <!--<add key="ReportViewerMessages" value="Microsoft.SharePoint.Portal.Analytics.UI.ReportViewerMessages, Microsoft.SharePoint.Portal, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />-->

2.   By default session is disabled in SharePoint. Enable it by ensuring an entry like below inside <system.web>.
<sessionState mode="InProc" timeout="60" />

3. Enable session at page level by setting the enableSessionState to true of <page…..> tag inside system.web.
<pages enableSessionState="true" enableViewState="true" enableViewStateMac="true" validateRequest="false" ……………………=""

4. SharePoint disable the default session module inside the <system.webserver>\modules tag. To enable the module comment out the following line inside <system.webserver>\moudles as shown below:
<!--<remove name="Session" />-->

Now if you try to put a reportviewer control in webpart/page, you will find a message as below:

Image

If you got/find above error message while accessing the report page then you are on right track. Please continue with following steps:

5. Add the following tag inside system.web\httphandlers section
<add verb="*" path="Reserved.ReportViewerWebControl.axd" type = "Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />

6. Add the following line in the system.webserver\handlers
<add name="ReportViewerWebControlHandler" preCondition="integratedMode" verb="*" path="Reserved.ReportViewerWebControl.axd" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />

7. Comment out the following line in the system.WebServer\httphandlers (If Exists)
<!--<add name="ReportViewerWebControl" verb="*" path="Reserved.ReportViewerWebControl.axd" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />—>

 

That's it..!! Error will be resolved now. Enjoy..:)

Friday, September 6, 2013

How to call Server Side Method from jQuery/javascript using Ajax & JSON Parsing

With this post I would show how to call server side method from client side. Here I use jQuery to utilize the Ajax Capabilities which will help us to get/post data to/from server Asynchronously. There are many methods available to perform an async callback to the server. Here I will show a simple example as in how to call a code behind Webmethod.
For simplicity I would be calling the code behind method on a Button Click. Here is the code:

<asp:Button ID="Button1" runat="server" Text="Click" />
<br /><br />
<div id="myDiv"></div>

JQuery/JavaScript Code to call Server Side Method:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js" type="text/javascript"></script>
<script type ="text/javascript">
$(document).ready(function () {
$('#<%=Button1.ClientID %>').click(function () {
$.ajax({
type: "POST",
url: "WebForm1.aspx/ServerSideMethod",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
async: true,
cache: false,
success: function (msg) {
$('#myDiv').text(msg.d);
}
})
return false;
});
});
</script>

Server Side Method (C# Code): (you must have to define your web method as public static)

[WebMethod]
public static string ServerSideMethod()
{
return "Message from server.";
}

In the above code, the aspx markup contains a button on click of which we would call the server side method named ServerSideMethod(). The div would show the message returned from the server. When you run the code above and click the button, it would the div would show the message "Message from server".
If you want to send parameters to your server side method / code behind method, you would replace the below line in the above jQuery code as:

data: "{'param1': 1}"    (Static Value)
data: "{'param1':"+ variableValue +"}" (If you want to pass Variable value

With the above line I would be sending a parameter with value as 1 to the server side method.
The server side method would change as:

[WebMethod]
public static string ServerSideMethod(string param1)
{
return "Message from server with parameter:"+param1;
}

You can also call your web service method from here URL attribute.
If you want to call your Web Method on confirmation box of Jquery then you can go with below code:

function MyConfirmMethod() {
if (confirm('Are your sure?')) {
$.ajax({
type: "POST",
url: "WebForm1.aspx/ServerSideMethod",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
$('#myDiv').text(msg.d);
}
});
return false;
}
else {
return false;
}
}

Server Side C# Method:

protected void Page_Load(object sender, EventArgs e)
{
Button1.Attributes.Add("onclick", "return MyConfirmMethod();");
}
[WebMethod]
public static string ServerSideMethod()
{
return "Message from server!";
}

Above you can see I am calling JavaScript confirm on the button click. On pressing yes, jQuery calls code behind method ServerSideMethod and returns back the message. You could perform any server side logic/database operations here based on the user response. Note I use return false as it prevents post-back to the server.

Thanks..:)

Tuesday, August 27, 2013

Session state has been disabled for ASP.NET. The Report Viewer control requires that session state be enabled in local mode

Solution for following error:Image

I had to install SharePoint Foundation 2010 for a new project. They needed a native Web Part, and the name of this was Report Viewer control

But a received a strange correlation-ID error and I could not open anymore my site. so I opened ULSVIEWER and got a stranger error: Session state has been disabled for ASP.NET. The Report Viewer control requires that session state be enabled in local mode

So I made some researches on internet and found always the same PowerShell Command:

Enable-SPSessionStateService ( "The only way to install ASP.Net Session State is through PowerShell using *-SPSessionStateService. [Enable | Disable | Get | Set]-SPSessionStateService" )

Reference:

Reference-1  Reference-2   Reference-3

The problem is that when I followed the directions for enabling session state using powershell, I could not find the cmdlet. I spent a ridiculous amount of time trying to figure this out since I had the correct powershell snapin, but I could not find that cmdlet.

 

To resolve this issue you need to change at 2 places.

     1. Do Following changes in your sharepoint web.config file

  • You need to edit the web.config file of the SharePoint application. Open your web.config and add the httpModules.

  • In the <system.web> section, find the <httpModules> element and edit it like the following:

  • <httpModules> <add name = “Session” type=”System.Web.SessionState.SessionStateModule” /></httpModules>

  • You also need to find the element tag <pages> (also under the <system.web> element) and look for the attribute called enableSessionState and set it to true if it is currently false. Save and close the web.config file.

 

     2. Now another thing is you need to add modules in IIS7

  • You should then open the IIS 7 manager, and select your web application.

  • Open the modules applet under the IIS section.

  • Click “Add Managed Module” in the right hand panel.Enter a name for the module, I chose “SessionState”, you can pick what you like, but I suggest something related to session state and then in the lower box, select the entry for:

  • System.Web.SessionState.SessionStateModule, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

Made an IISreset, and test again. you can now add your WebPart Report Viewer control to your site.

Monday, July 8, 2013

How to send requrest after executing Response.End() statement

Once I have to create a custom search on list item for some of the item fields and then it can be exported to excel. I successfully developed a custom visual web part which display only those record which fulfilling the search criteria and is transferred to excel. But then i face one problem that first time when i search the record and export it to excel it works fine. But for the second time my request is not sent to server because of using Response.End() function to avail the user to download the exported record in excel file.


So following is the solution for the same. Add below JavaScript in  your web part design page.


<script type="text/javascript">
document.ready({
        _spOriginalFormAction = document.forms[0].action;_spSuppressFormOnSubmitWrapper = true;
});
</script>

and append following code in your page load event.


System.Web.UI.ScriptManager scriptManager = System.Web.UI.ScriptManager.GetCurrent(this.Page);
scriptManager.RegisterPostBackControl(this.btnToExport);

Please replace this.btnToExport with your button or your control on which you handle click event to export it to excel.


 

Monday, July 1, 2013

How to decrease Content DB Size

If your content DB size is more than its actual size then you have to remove items from your Recycle Bin.

Once you remove your item from Site Action -> Recycle Bin it will transffered to Admin Recycle bin. You have to remove it from there also.

http://yoursite/_layouts/AdminRecycleBin.aspx?View=2

Once you removed your data from here now see the size of your content db. Its reduced now.

Thanks.