Tuesday, 27 March 2012

Auto Populating the User Information to the repeating table from the custom list


STEP 1:


STEP 2:
Goto DataTab à Click Data Connection


Select your list:



Select your fields:


Click Next à Finish
STEP 3:

Click Data Tab à Select Form Load

Select the Rule

New à Action




STEP 4:
Select the Condition à Click the field or group




STEP 5:
Select the Secondary option


Select Login Name


In Next select the Main


Choose the UserName option


STEP 5:


Click Field:



Click Value:

àClick Insert Field or Group & Choose the secondary option



è Click Filter Date & Click the ADD button

In first Dropdown box choose the secondary option(Login Name)
      Is equal to

      In second Dropdown box choose the Main option(User Name)


   STEP 6:

    Set another  field's value has done before



Click Field:



Click Value:

àClick Insert Field or Group & Choose the secondary option



è Click Filter Date & Click the ADD button

In first Dropdown box, choose the secondary option(Login Name)

Is equal to

In second Dropdown box ,choose the Main option(User Name)


STEP 7:

 Set another field's value has done before



Click Field:


Click Value:

àClick Insert Field or Group & Choose the secondary option


è Click Filter Date & Click the ADD button

In First Dropdown box ,choose the secondary option(Login Name)

Is equal to

In second Dropdown box ,choose the Main option(User Name)


STEP 8:

 Set another field's value has done before


Click Field:


Click Value:

àClick Insert Field or Group & Choose the secondary option


è Click Filter Date & Click the ADD button

In  first Dropdown box choose the secondary option(Login Name)

Is equal to

In second Dropdown box choose the Main option(User Name)




STEP 9:

Publish your site


STEP 10:

The output will be  displayed as shown below:











Friday, 23 March 2012

10 InfoPath tips for SharePoint developers

Here are 10 nice tips designed for someone that's familiar with SharePoint, but may be new to InfoPath.


Having brooded over the idea for a while, I decided to quickly write this down, and if there are any questions I can expand some of these key points.



  1. Use InfoPath Designer 2010 to author your forms, even for 2007 forms. The UI is better, design checker gives you more information, and the rules editor supports copy/copy all and paste.
    Note: design checker gives you a lot of warnings and sometimes... they can be ignored. Which ones are safe and which aren't... is as far as I know, a personal experience thing, think of it as VS.NET warnings.
  2. Design your main context fields first, and then try your best not to change existing fields (add new fields are OK). Removing or renaming fields often break existing forms that had already been filled out.
  3. Decide upfront whether this is a rich form or a browser form, and set the compatibility level appropriately. Use the design checker.
    If you are planning to create hybrid forms that works on both - there's a form option that will allow your code behind to use the Rich Form API but still check the form for Browser Form compatibility. In this case, always check in your code whether the form is running in the browser before you call those APIs, otherwise you will get UnsupportedExceptions.
  4. If you need to promote InfoPath fields to SharePoint so they appear as columns (and can be used in workflows), you should always use site columns. You might want to consider always using Content Type as well.
    It may be tempting to use publish to list - but this creates list fields that are now very hard to manage, and when you realize down the road that you should have used content types, you now have to fix existing list columns and move their data to the site columns. This always happens.
  5. Brush up on your XPath skills well. InfoPath renders every view via a XSLT transform and the output is actually a HTML page (either for rich form or web forms). You need to use XPath when you want to start defining rules that are relative to the current field. Why use rules when you can use code behind? See next point.
  6. Code behind are powerful, and may look much simpler to a developer, but has deployment considerations. In 2010, code behind can run either in a farm solution, or via the sandbox user code service. However, code in the sandbox service sometimes may not run when the service is "busy". Your best bet is either: deploy code through central administration - if you have access, but then you trip up tip #4 if you haven't been using site columns, or don't use code behind and write your logic using only rules. You can find detailed InfoPath documentation for developers on MSDN (it may not look like much, but you have functions like get-SharePointServerRootUrl that are just gems hiding)
    Plus, trust me you feel awesome when you can write complex logic using declarative XPath and no C# code. It's like saying yes I could cheat and just use C#, or I can be godlike and do it in XPath.
  7. Copying pictures increases your resource size. The best way for a repeated picture is to include it as a resource, then use a picture button and set the image to your included resource. Unfortunately you can't set the image of a picture control.
  8. Export form as Source files, and work with the manifest.xsf. While I'm pretty certain it is unsupported to tweak the view.xsl files manually by hand, at least you can now put all the component files within a source control and check what has changed using a simple text difference tool.
  9. Learn how to call webservice with Rules. InfoPath is pretty dumb beyond what's within the form. Webservices gives you lots of capabilities but only if you know how to call them. E.g. how to interact with SharePoint users.
  10. Don't use the "can't be blank" option, always create validation rules. When any validation rules fail, it puts the form into an invalid state and prevents any submit action. If you have them all defined as validation rules - you can add an additional condition that allows saving E.g. if ForceSave = "0" and "MyField" is empty
    This gives you control over what happens when the user is trying to save, and allow you to disable the checking when you need to.

Deploy SharePoint Solutions

Deploy SharePoint Solutions



stsadm command could be used to add a SharePoint solution to SharePoint:




stsadm –o addsolution –filename “D:\Deploy\MySharePointSolution.wsp


We used the following command to deploy the solution once installed to a specific web application:


stsadm –o deploysolution –name MySharePointSolution.wsp –url http://myspwebappp –allowgacdeployment –immediate


If we would upgrade an existing solution, we would use the following:


stsadm –o upgradesolution –name MySharePointSolution.wsp –filename “D:\Deploy\MySharePointSolution.wsp” -immediate



And finally, we used the following commands to retract and delete a specific solution from the web application:


stsadm –o retractsolution –name MySharePointSolution.wsp –url http://myspwebapp –immediate

stsadm –o deletesolution –name MySharePointSolution.wsp


Now, let us see how we could do above operations with PowerShell. For this, we use the following PowerShell commands:


Add-SPSolutionD:\Deploy\MySharePointSolution.wsp


Install-SPSolution –Identity MySharePointSolution.wsp –WebApplication http://myspwebapp –GACDeployment


If you would like to add the solution as sandboxed, you would use the Install-SPUserSolution command instead. To upgrade a solution, we specify which solution is to be updated and with which new solution file:


Update-SPSolution –Identity MySharePointSolution.wsp –LiteralPath “D:\Deploy\MySharePointSolution.wsp” –GacDeployment



To retract and remove a solution, we use the following commands:


Uninstall-SPSolution –Identity MySharePointSolution.wsp –WebApplication http://myspwebapp

Remove-SPSolution–Identity MySharePointSolution.wsp


Working with features


Similarly, commands exist for working with features. The stsadm equivalents:



stsadm –o activatefeature –name MyFeatureName –url http://myspwebapp

stsadm –o deactivatefeature –name MyFeatureName –url http://myspwebapp


Needless to say, there are easy equivalents in PowerShell:


Enable-SPFeature –Identity MyFeatureNameOrGuid –url http://myspwebapp


Disable-SPFeature –Identity MyFeatureNameOrGuid –url http://myspwebapp

SharePoint 2010: Backup/Restore with PowerShell Command

SharePoint 2010: Backup/Restore with PowerShell

If you want to backup/restore your site collection in SharePoint 2010, you can do with PowerShell command. I’ll spilt the post in two sections. One is on how to backup/restore in the same site collection and another is how to backup from one server/site collection to another. For the former (backup/restore in the same site collection), SharePoint provides nice easy GUI page in Central Administration page. However, for second one (backup/restore between different server) you need to run PowerShell scripts.

Backup/Restore in the same server and same site collection


Sometimes you may want to backup from a site collection and your intention is to restore the backup in the same site collection. One example might be you have a site collection, say “http://myserver” and you are going to run code to test something against the site. However, you fear that running the code may break something and before you run the code, you want to backup the site so that in case running the code breaks something you can restore the backup taken before running the code. In the case, where you need to backup/restore is centered around same server and site collection, you can take SharePoint Central administration UI to do the backup/restore.

Backup Steps

1. Navigate to the Central Administration => Backup and Restore

2. Under “Farm Backup and Restore” section click “Perform a backup”.

3. Now you’ll be landed in the following page where you can select the site or site collection you want to take backup:

image

4. Click next and you’ll be navigated to the following page where you can select backup type (full or differential) and backup location:

image




Restoring Steps

To restore follow the steps:

1. Navigate to the Central Administration => Backup and Restore.

2. Under “Farm Backup and Restore” section click “Restore from a backup”. Follow the wizard to restore from a backup.



Backup/Restore from one server to another or from one Site Collection to another (with PowerShell command)


In some cases, you have developed a SharePoint site collection in your dev or stg machine and now you want to move the site with data from dev/stg to production. In such cases the process shown in the section “Backup/Restore in the same server and same site collection” will not work. The recommended way is to use PowerShell command to take backup and restore the backup.

Backup a Site collection with PowerShell command

In SharePoint 2010, PowerShell command Backup-SPSite is used for taking backup. you can get details of the command from the msdn link. The following command will backup the site collection ‘http://myserver’.

Backup-SPSite -Identity http://myserver -Path "c:\backup\file.bak"

Restore a Site Collection with PowerShell command

To restore site collection you’ll use the following command. Use –Force if you want to overwrite the existing site collection

Restore-SPSite -Identity http://myserver -Path "c:\backup\file.bak"

However, once I had restored the backup I could not access the site. The problem was that I needed to deploy the custom SharePoint solution. So in case of site collection migration (with backup/restore) from one server to another or from one site collection to another, the steps should be:

    1. Restore the backup.
    2. If your source site collection (from where you taken backup) uses custom SharePoint solution, then deploy the solution in the destination site collection (where you are restoring the backup). If you try to access the site without deploying solution then you may get the site non-functional.
    3. Now you can try to access the site.

    The important point here is that if you take backup from one server to another and restore it, the custom solution related to backup doesn’t go with backup. So after restoring backup you need to manually deploy the solution on the destination server. Then it’ll hopefully work.

    Migration SharePoint 2007 to SharePoint 2010

    Migration SharePoint 2007 to 2010



    Prerequisites for migrating SharePoint 2007 site to SharePoint 2010:1. Check whether the packages (wsp features etc) in source server are same as in the target server (if not please install).
    2. Check the web.config modifications made in the MOSS 2007 site (source site), if any do the same modifications on MOSS 2010 site (target site) accordingly.

    Migration process:

    The only process to migrate the site from SharePoint 2007 to SharePoint 2010 is the migrating contentDB of source site to target site.

    Steps to follow for migrating ContentDB:

    1. Take the backup of the source site contentDB and restore the same on target server.
    2. Create the web application in SharePoint 2010, and then create the site collection (it doesn’t matter what site template you are using for creating site collection).
    3. Once finished creating the SharePoint 2010 site, go to central administration --> Manage content databases --> select the web application you created for migration --> click on database --> check in the remove content database --> click ok

    4. Add the restored database in the target site by using stsadm.exe in command prompt


    stsadm –o addcontentdb –url “enter your url” –databasename “enter your db name”

    5.Restart IIS.

    Note: Type the stsadm command manually don't copy paste bcoz Sometime not working.

    How to Create an ASMX Web Service on SharePoint 2010, Using Visual Studio 2010



     Back in SharePoint 2007, asmx web services were quite prevalent, thanks to the WSPBuilder tool, and it’s templates.   They are useful for executing actions between multiple web applications and can be used by client applications, as well.  Furthermore, InfoPath forms, deployed to SharePoint, could also use these asmx web services.

    Unfortunately, Visual Studio 2010 did not come with a template for SharePoint web services.  So, today I will be writing about how we can create asmx web services for SharePoint 2010.  All you will need is SharePoint 2010.

    First, start a new Empty SharePoint 2010 project.  I will call this SPASMXService.


    Make sure to deploy it as a farm solution.


     First, you need to close this project by right clicking on the project and then selecting ‘unload project’.



    Then, right click on the project again, and select, ‘Edit SPASMXService’.


    Under <SandboxedSolution>False</SandboxedSolution> type in:

    <TokenReplacementFileExtensions>asmx</TokenReplacementFileExtensions>

    This will be the result:


     Then, save and close out of this xml file.  This will allow Visual Studio to insert the solution information where necessary.  Therefore, this is a crucial step!  Finally, reload the project file.




    Next, we will be creating the web service.  Right click on the project, and select “Add” and then select “New Class…”  This will be the code behind.  Let’s just call this SPASMXService.cs.





    Now, open SPASMXService.cs, and make the following changes:

     


    This is a good start for a web service with a web method.  Now, of course we have a few errors because we still have not brought in the necessary libraries.  Right click on ‘references’ in the Solution Explorer, and select, ‘Add Reference’.  Select System.Web.Services from the .NET tab.  Then, in SPASMXService.cs, add, ‘using System.Web.Services’.  This should look like this:






    Finally, we have to create the service page.  I like to keep it in the _layouts folder, but you can keep it elsewhere using similar steps.  Right click on the project item in the solution explorer, and select add -> SharePoint “Layouts” Mapped Folder.




    You can also select SharePoint Mapped Folder, and then select ISAPI.  This would cause the page to go into _vti_bin instead.

    For now, I’m going to stick to _layouts:






    The SPASMXService folder was automatically made.  Nice.


    Inside the SPASMXService, under Layouts, we will add a new file of type xml.  We Shall call it SPASMXService.asmx.








    The contents of SPASMXService.asmx will be a single line:

     <%@ WebService Language="C#" Debug="true" Class="[Class path], $SharePoint.Project.AssemblyFullName$"  %>

     Where [class path] is the full namespace name of the SPASMXService class in SPASMXService.cs.  In my case, the line will be:



     From:

     

     Finally, save everything, and then deploy the solution.





    If everything went right, you should see this using Internet Explorer:




    If you used ISAPI instead of Layouts, _layouts in that screenshot should be _vti_bin, instead.  If you opened this from a front end server with web service, then you can further test this web service by clicking on that link.



    Lastly, a bit of trouble shooting; you can check on the web service page by going to:



    C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS



    If you used ISAPI instead of LAYOUTS, then instead go to:



    C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI



    If the web service does not load on Internet explorer, then you should open the asmx page from one of these two locations.  If you open the asmx page from one of these two locations, and you still find “$SharePoint.Project.AssemblyFullName$”, then you need to go back to the top of this article and follow the steps regarding unloading and reloading the project.


                                                                          Best of luck!






    SharePoint online - Get List-item attachments and Display to div

    Step 1 : Create a List ex: TestList and attach few images Step 2 : Copy and Pastet the below coding in App.js var  Items =  null ; ...