Feeds:
Posts
Comments

There are two methods we can use to insert a list-item out-of-the box. Those methods are using the web-service and using the object model.
The consideration when to use the method is whether the form will be executed within SharePoint context or it will be executed outside SharePoint.
If you are going to use within the SharePoint context, you can use Object-Model or Web-service otherwise.

Today, I’ll show on how to insert a list-item to a list in SharePoint using the object model.

STEP 1: CREATE A BLANK FORM IN INFOPATH FORM.

STEP 2: CREATE A CUSTOM LIST WITH THE FOLLOWING FIELDS. (Employee Details)

FIELD’S NAME  TYPE    InfoPath Field’s name  Data Source’s type 
First_Name  Single Text    Txt_FirstName  Textbox 
Last_Name  Single Text    Txt_LastName  Textbox 
Mobile_Number  Single Text    Txt_MobileNum  Textbox 
List Name: Employee Details   InfoPath form’s detail 

 

STEP 3: CREATE A DATA CONNECTION FROM INFOPATH.

  1. Create an InfoPath 2007’s form as the following picture.

 

  1. Click Tools – Programming – Microsoft Visual Studio Tools for Applications

 

  1. We need to reference Microsoft.SharePoint.dll to our VSTA. It can be found under:
    C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\ISAPI

     

 

  1. Click Tools – Form Options – Security and Trust.

    Tick off “automatically determined security level (recommended)” and change it to Full Trust.

    Tick on “Sign this form template” – Create Certificate if you haven’t got a certificate yet.

 

  1. Now let’s start the fun part. Right-Click – Properties on the submit button. Add the following function underneath the CTRLX_X_Clicked’s event.
private void InsertListItem(string FirstName, string LastName, string MobNum){

SPSite Myportal = new SPSite(“http://your_servername”);

SPWeb myWeb = Myportal.OpenWeb();

SPListCollection ListCollection = myWeb.Lists;

SPList EmployeeDetails = ListCollection["Employee Details"];

 

SPListItem newItem = EmployeeDetails.Items.Add();

newItem["First_Name"] = FirstName;

newItem["Last_Name"] = LastName;

newItem["Mobile_Number"] = MobNum;

newItem.Update();

 

//Disposing unused objects.

Myportal.Dispose();

myWeb.Dispose();

 

  1. Then add the following code inside the clicked’s event
XPathNavigator main = MainDataSource.CreateNavigator();string _firstname = main.SelectSingleNode(“/my:myFields/my:txt_FirstName”, this.NamespaceManager).Value;

 

string _lastname = main.SelectSingleNode(“/my:myFields/my:txt_LastName”, this.NamespaceManager).Value;

 

string _mobNum = main.SelectSingleNode(“/my:myFields/my:txt_MobPhone”, this.NamespaceManager).Value;

 

InsertListItem(_firstname, _lastname, _mobNum); 

 

  1. That’s it.

 

Try to run the code by pressing the green arrow button. When the blank form is displayed, fill in the form and click Submit button.
Since we haven’t implemented any successful / unsuccessful method, then it will not show anything. To find out if you have successfully submitted
the item, please open up the list. You should be seeing the entry. For my scenario it shows:

 

Tomorrow I will show you on how to upload the infopath form to the document library as the InfoPath Form services.

Today I’ve got a task from my client to “simplify” a long, ugly, hard to remember URL to a user friendly URL.

His URL was: http://big_company/sites/headoffice/it/projects/oracle/phase1 , and now it has become similar like: http://phase-1.it.projects.

If we would like to have an alternate access mapping per web application, it is quite straight forward, but how can we get an alternate access mapping on site collection’s level?

That is easy. Just follow these 3 simple steps.

For example, you would like to have a friendly URL from

http://server_name/sites/projects/accessrequest into http://accessrequest.projects

STEP 1: CREATE THE SITE COLLECTION

stsadm -o createsite -url http://accessrequest.projects :80

-ownerlogin on3OnSharePoint\administrator

-owneremail administrator@on3onsharepoint.com

-hhurl http://on3onsharepoint:80

-sitetemplate STS#1

-title “Access Request “

You don’t need to specify the port number if you are using port 80, I put the port number just in case you guys get confuse whether if we can create on another web application or not.

STEP 2: IMPORT YOUR OLD CONTENTS (OPTIONAL)

If you are moving from your old long URL into this new site collection, then you should move all your contents to this new home. You can use SPContentDeploymentWizard from www.codeplex to help you migrating all your contents.

STEP 3: CREATE A DNS ENTRY

You must create a host (A) record’s DNS entry in your DNS server which should be pointing at http://accessrequest.projects and your sharepoint’s server.

That’s it. Easy nice simple. Hopefully helps you guys.


Have you ever wondered on how to customize The People Search’s result?

I spent almost a day to find out and get this working as expected, and now i put this on my blog, hopefully other people can use this and not spend as much time as I did :)
Let’s start …

What you need to accomplish this walkthrough are:
a. Microsoft SharePoint Designer 2007.
b. MOSS 2007 with People Search enabled.
c. Administrator access on the site collection.
d. For this walk-through, I am using Active Directory Properties that i have imported from the
Central Administration, but you can use other properties which are available in your Farm.
I will customize the search result that will display

  • Preferred Name (Default)
  • Job Title (Default)
  • Phone Number, Mobile Number, Fax Number (add them manually)

Step By Steps:

  • Open up your Search Centre site.
  • Search one of your friend or maybe search yourself.
  • When the search result is displayed, Click Settings – Edit Page.
  • In People Search Core Result, Click EditModify Shared WebPart
  • In Results Query Options there is a textbox named”Selected Column“, Click on that textbox, the it will show its elipsis [ ... ] next to it.
  • Add “<Column Name=”[Metadata mapping]” /> before the “</Columns>
    For this example, my Selected columns are:
<root xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”>

<Columns>
<Column Name=”AccountName”/>
<Column Name=”UserProfile_GUID”/>
<Column Name=”PreferredName”/>
<Column Name=”JobTitle”/>
<Column Name=”Department”/>
<Column Name=”WorkPhone“/>
<Column Name=”PictureURL”/>
<Column Name=”WorkEmail”/>
<Column Name=”MobilePhone” />
<Column Name=”Fax” />
<Column Name=”OfficeStreetAddress” />
<Column Name=”OfficeSubUrbLocation” />
<Column Name=”OfficePostalCode”/>
<Column Name=”OfficeCountry”/>

</Columns>

</root>

  • If you scroll down a little bit, you’ll see “Data View Properties“, Click the “XSL Editor“.
  • Change the code with:
<?xml version=”1.0″ encoding=”UTF-8″?>

<xsl:stylesheet version=”1.0″ xmlns:xsl=”http://www.w3.org/1999/XSL/Transform”>

<xsl:output method=”xml” version=”1.0″ encoding=”UTF-8″ indent=”yes”/>

<xsl:template match=”/”>

<xmp><xsl:copy-of select=”*”/></xmp>

</xsl:template>

</xsl:stylesheet>

  • Click OK.
  • Don’t PANIC
  • Click – EditModify Shared WebPart, then you will see similar like the picture below. Copy All of them and save them as
    SearchCore.xml
    locally in your hard-drive.
  • Open up your site (any site) with Microsoft SharePoint Designer 2007.
  • Click FileNew. Choose ASPX.
  • Click Task PanesData Source Library.
  • Click “Add an XML File” under” XML Files“, Select the SearchCore.Xml that we created in Step 11.
  • In the Context-Menu associated with SearchCore.xml, choose “Show Data
  • Choose all fields you would like to show in the search’s result – click Insert Selected Field as … – Choose “Single item view
  • Now you can use your HTML & CSS Skills to edit the look and feel.
  • Once you have done that, Click “Code” at the bottom.
  • Copy Paste the code from:
<xsl:stylesheet version=”1.0″ exclude-result-prefixes=”xsl msxsl ddwrt” …. xmlns:ddwrt2=”urn:frontpage:internal”>

Until you find the end of the tag. [</xsl:Stylesheet>]

  • Now go-back to 7, Find the “XSL Editor” and change the code with the one you have just copied.
  • Click OK.
  • You will see one error similar to step 9, re-do the steps until step 11.
  • Publish the page.

You should see your customized result’s page.

Hopefully it will help you.

Feel free to comment on my blog.

Thanks.