Software Engineer

My photo
Colombo, Sri Lanka
B.Sc.Special(Hons)in IT, MCTS, MCPD, MCP

Monday, May 27, 2013

Add a robots.txt file to SharePoint 2010

What is robots.txt?

This(robots.txt) is a text (not html) file placed in the root of your site to tell search robots which pages should and should not be visited/indexed. It is not mandatory for search engines to adhere to the instructions found in the robots.txt but generally search engines obey what they are asked not to do.

Web site owners use the /robots.txt file to give instructions about their site to web robots. This is called The Robots Exclusion Protocol.
It works likes this: a robot wants to vists a Web site URL, say http://www.example.com/welcome.html. Before it does so, it firsts checks for http://www.example.com/robots.txt, and finds your robot.txt file.

Creating a Robots.txt

    1. Launch Notepad
    2. Put the following in your robots.txt file:
          

      User-agent: *
      Disallow: /
   
    3. Save the file as: robots.txt 

The "User-agent: *" means this section applies to all robots. The "Disallow: /" tells the robot that it should not visit any pages on the site. 

Adding the robots.txt file to the root of your public anonymous SharePoint site.

The location of robots.txt is very important. It must be in the main directory because otherwise user agents (search engines) will not be able to find it. They do not search the whole site for a file named robots.txt. Instead, they look first in the main directory (i.e. http://www.sitename.com/robots.txt) and if they don't find it there, they simply assume that this site does not have a robots.txt file and therefore they index everything they find along the way. So, if you don't put robots.txt in the right place, don't be surprised that search engines index your whole site.

To do this, you can simply follow my article Add a file to the root of a SharePoint site using PowerShell

Ensure the file is accessible to search engines
  
To ensure the file is accessible to search engines go to your site URL and append "/robots.txt".
      
      Example: http://www.sitename.com/robots.txt

Also you can use Robots.txt Checker to do this.

There are two important considerations when using /robots.txt:

  • robots can ignore your /robots.txt. Especially malware robots that scan the web for security vulnerabilities, and email address harvesters used by spammers will pay no attention.
  • the /robots.txt file is a publicly available file. Anyone can see what sections of your server you don't want robots to use.
So don't try to use /robots.txt to hide information.

Thursday, May 23, 2013

Add a file to the root of a SharePoint site using PowerShell

Sometimes you need a file to be right off the root of your Internet facing SharePoint site. Files like robots.txt, sitemap.xml. To do this we’ll take advantage of PowerShell’s ability to use any .NET methods along with the Files collection on each SPWeb in SharePoint.

Copy the following syntax and change the values marked in red color according to your need. In the first one give the full path to your file. In the second place with this file name you are going to save your file in the root.

$fileBytes = [system.io.file]::ReadAllBytes("c:\the\full\path\to\your\file.txt");
$site = Get-SPSite "http://sharepoint1";
$site.RootWeb.Files.Add("robots.txt", $fileBytes, $true);


Open the PowerShell as administrator then just copy and execute.
This will result in a robots.txt located at “http://yourdomain:portifneeded/file.txt”.

Be Happy !!! :)

Schedule a Site Collection Backup with a PowerShell Script - SharePoint 2010

I will demonstrate how to back up a SharePoint 2010 site collection automatically through the use of a Power-Shell script. My challenge is How can I backup a SharePoint 2010 site collection automatically on a regular basis?

Here is the solution.

Step 1.

  First setup a backup location. It can be "C:\Backup\MySite" or a shared location like
  "\\MYPC\Backup"

Step 2.

  Then, verify that you possess the following permissions:
  • SharePoint Farm Administrator.
  • Local Server Administrator on all Web servers.
  • db_owner permission on the content database.
  • Full Control permission on the backup folder.

Step 3.

Download this Power-Shell script for backing up a site collection and change the values according to your environment. Replace "$mySite" with your site collection URL and "$backupLocation" with your backup location. My script name is "BackupSite.ps1".

Download "BackupSite.ps1"

Basically, the above script will do the following:
  • Assign all the needed information to start backup.
  • Try to create a new backup and name the file based on current date.
  • If successful, it will write a success message to the log file. Otherwise, it will log the error/exception.

Step 4.

Download the batch file to run the script from following link. (To create a batch file, open a notepad, add these lines and then save it with ".bat" extension)
Download "RunBackup.bat"

Step 5.
 
Copy both the script and batch file to a folder on the SharePoint Server.

Step 6.

Run the batch file to start backing up the site collection immediately or use Windows Task Scheduler to schedule it.
I have attached both the script and the batch file for your convenience.

Notes:
  • This method works with both SharePoint 2010 Foundation and Server.
  • While performing the backup, the SharePoint site collection will be set to Read-Only to prevent data corruption, so it's recommended that you run this script during off-peak hours.

Tuesday, January 15, 2013

SharePoint Storage Limits, SharePoint 2007 vs SharePoint 2010

How many lists can you have per website? In SharePoint 2010, the recommended limit is 5,000 and you can have up to 2,000 in SharePoint 2007

How many items can you have in a folder? In SharePoint 2010, you can have up to 5,000 items and in SharePoint 2007, the recommended limit is 2,000 items per folder.

How many files can you have in a document library? In SharePoint 2010, the maximum number of documents per library is 30,000,000. You can create very large document libraries by nesting folders, or using standard views and site hierarchy. This value may vary depending on how documents and folders are organized, and by the type and size of documents stored. The limit in SharePoint 2007 is 10,000,000 and having more than 50 lists and libraries in the site’s navigation structure makes it more difficult to navigate the content by using the user interface.

What is the size limit for SharePoint’s content database? The content database limit in both SharePoint 2010 and 2007 is 200 GB for collaboration and 1 TB for document archive. In general, we strongly recommend limiting the size of site collections to 100 GB for better site performance.

How many users can there be in a site collection? You can have up to 2 million users per site collection in SharePoint 2010 as well as in SharePoint 2007.

What is the file size limit?  The default maximum file size is 50 MB in SharePoint 2010; however, this can be increased up to 2 GB. Remember that a large volume of very large files can affect the performance of your site. This hasn't changed from SharePoint 2007. The file size limit in 2007 is also 2 GB.

Original Article : http://corebix.com/top-six-questions-about-sharepoint-storage-limits-sharepoint-2007-vs-sharepoint-2010


Tuesday, January 8, 2013

Get Current Users Account Details to InfoPath

Today we'll look at retrieving current users' Information as well as naming the infopath files using the fields on the form.
for the sake of length, I'll divide this post in two part.

In this part, we'll see how to get current users' profile properties in Infopath Browser forms using UserProfileService.asmx

Let's consider an example called Product Request Form where a particular sales employee of the company request for shipment of a particular product

1. First Open the Infopath( this can be done by simply typing 'infopath' in run prompt) and choose a blank template to start with. Make sure you have selected Enable Browser Compatible Features only



2. Add Following Fields to the Main Data source




products: Text
expectedDate: Date
CurrentUserName: Text
IsFormLocked: Boolean
fileName: Text
Error: Text


3. Create the form Layout as below:



Lets insert Some values in the products dropdown:



4. Firstly, we have to get the Current user's name in the Requesting User text box
and the text box be read-only. For this, we will consume the SharePoints' much hyped userprofileservice.asmx's method called GetUserProfileByName

5. For this, go to Design Task -> Data Source -> Manage Data Connections -> Add...
In the Wizard:
a. Choose Create a new connection to: Receive data


b. from the Source of Data, select Web Service


c. In Url, enter your Sites' url follwed by _vti_bin/UserProfileService.asmx


d. Out of the list of methods, choose GetUserProfileByName


e. In Next screen, you'll be asked for Account Name, leave it blank as doing so would get the current User.


f. Make sure in consecutive screens that Store a copy of the data in the form template is unchecked and Automatically retrieve data when form is open is checked

6. In the text box mapped to the field CurrentUserName, we would need to format the display value to that retrieved from UserProfileService.asmx
thats configured to populate its values on form Load. For this, go to Textbox's properties and in the Value field, go to formula builder by clicking fx



7. Click Insert Field or Group.... Choose the secondary receive data source we just created and select value field but don't click Ok yet!!



8. Instead, click on Filter Data... -> Add... to open the filter condition dialog and choose Select a field or group...



9. Choose Name Field again from the Secondary Data Source just created:



10. In the second drop down, select is equal to and in the value drop down, choose Type a Text... and type AccountName



Note: you can choose from a list of profile properties you want:
UserProfile_GUID
AccountName
FirstName
LastName
PreferredName
WorkPhone
Office
Department
Title
Manager
AboutMe
PersonalSpace
PictureURL
UserName
QuickLinks
WebSite
PublicSiteRedirect
SPS-Dotted-line
SPS-Peers
SPS-Responsibility
SPS-Skills
SPS-PastProjects
SPS-Interests
SPS-School
SPS-SipAddress
SPS-Birthday
SPS-MySiteUpgrade
SPS-DontSuggestList
SPS-ProxyAddresses
SPS-HireDate
SPS-LastColleagueAdded
SPS-OWAUrl
SPS-ResourceAccountName
SPS-MasterAccountName
Assistant
WorkEmail
CellPhone
Fax
HomePhone


11. Finally, your formula should look something like this:



12. I Guess, this is it, for getting the current users' loginName.. you could have opted for any properties from the list of available properties above.



Original Post by Adil A. Baig.
http://baigadil.blogspot.com/2008/07/get-current-user-for-infopath-and-set.html

Monday, September 24, 2012

Limitations of External lists in SharePoint 2010

We can't compare external lists with standard lists where data is stored inside of SharePoint. Since the data is stored outside SharePoint, there are many Limitations in External Lists. Many of the Ribbon features will not be available for external Lists.
  • Datasheet view is not available
  • Export to Excel option is not available
  • Workflows cannot be configured for External Lists
  • Cannot create Information Management Policies (bar codes,  auditing, retention or labels)
  • No version or version history
  • Inline Editing is not available
  • No Ratings widget
  • Can't create Visio Diagrams
  • Open with Access/Open with Project is not supported
  • REST access via ListData.svc to External Lists is not available (All WCF services like RSS feeds are not available)
  • No Look ups
  • No Context Menu (ECB) Send To operations.
  • Events handlers are not supported.
    LINQ to SharePoint spmetal.exe does not support external lists
  • No Item Level Permissions
  • No item or field level validation or Formula supported
  • Document templates are not supported.
  • Alerts are not supported
  • Attachments will not be available
  • Additional data connections in InfoPath 2010 list forms not supported
  • My favorite Utility: U2U CAML Query builder doesn't work!
  • No Check In / Check Out options 
  • Drafts of items are not supported.
  • No Write support for BLOB 
  • Metadata based navigation is not supported
  • You cannot mix the SharePoint columns with External List columns since they are coming from external source.
link to Original Blog Post by Salaudeen Rajack : http://salaudeen.blogspot.com/2012/03/limitations-of-external-lists-in.html

Friday, September 7, 2012

Create Auto-Increment number column in SharePoint List

Hi Everyone,

This is a common problem faced by lot of guys who has a little programming knowledge. I am going to explain a simple way to crate a auto-increment number column in a custom list without programming. Every time insert an item to the list this will add a unique auto-increment number to column to track the record.

Start out by creating a new column in the SharePoint list you want to have the  auto-increment number in. This must be a number column. Name this whatever you like. The list that i'm using is " Help Desk Tickets" and my column is "Ticket No"


Then create a custom list with any name you want. My one is "Counter".


Counter list has 4 columns Title, Counter, Last Number, Next Number. Title is default Title column. Counter is Single Line of Text column. Last Number is number column and Next Number is a calculated column.

After creating the Counter list I am going to add a new item to the list.


Remember Last Number should be the number BEFORE the one you want to start on. When you added the new item notice the Next Number it now counts +1 from the Last Number.

OK. Then go to the list you are wanting the auto-generated number in, in my case it is "Help Desk Tickets". Open the list in SharePoint Designer. Click "List Workflow" button in the top left corner.


Give a name to the workflow. My workflow is "CounterWorkflow". In the workflow Start Options tick that "Start workflow automatically when an item is created". If you want you can tick "Start workflow automatically when an item is changed" also. It will give a new auto number to changed items too.

Before we start writing the workflow I will create a local variable. To create it click on the "Local Variables" button. Click Add button. Click Name and name it something. I am using "mNumber" as the name and Type is Number.


Click OK. Now you have created a variable called mNumber. This will be used to store our Next Number information so it can be manipulated without actually touching the Next Number fields.

Lets write the workflow.

1. Click on conditions and in common conditions add "if current item field equals value" condition.
In that condition click the "field" and add Title. Click "equals" and add "is not empty".

2. After that click on Actions and in Core Actions add "Set Workflow Variable". Click on "workflow variable" and add "mNumber". Then click on the "value" and click the function button. Select the "Data Source" as "Counter" and "Field From Source" as "Next Number". In "Find the list item section" in message box "Field" is "Title" and type the value as "LTL Folder Number". It looks like following.


When you click on the OK button it will give a warning like this.


Don't worry about it and click on "Yes".

3. Then add another Action. Click on Actions and in List Actions add "Set field in current item". In the action click on "field" and add the number column you want to increment automatically. In my case it is "Ticket Number". Then click on "value" and click on function button. Select the "Source" as "Workflow Variables and Parameters" and "Filed" as your variable. So my field is "mNumber".


4. OK lets add our last action. Click on Actions and in List Actions add "Update List Item". Click on "This List", In the message box select your auto-number list. My one is "Counter". Click "Add" button and select "Set This Field as" "Last Number". Then click on function button in "To This Value".


In the popup select "Workflow Variables and Parameters" as "Data Source" and my variable "mNumber" as "Field from source". You can select your variable.


Then click "OK". Now it looks like this.


Next click on "Field" and choose "Title". Type "Value" as "LTL Folder Number", our new item in the list counter.Now it looks like this.


When you click on the OK button it will give a warning. Don't worry about it and click on "Yes".

We now have a workflow that will pull Next Number from your Counter list. It will then copy it in to the variable and apply the variable to your main list column. Then it will copy the variable back over to Last Number, causing Next Number to increment by 1 or whatever value you choose.

Finally the workflow looks like this.



You have now created a new list and workflow. Now your main list will have a column that auto counts in increments of 1 each time the item is created or based on your conditions.

So now when I add new items to my "Help Desk Tickets", "Ticket No" is auto generated as following.


Have A Nice Day My Friends.

Regards,
Gihan Maduranga.