SharePointAds TextOnly

Thursday, 22 April 2010

How to insert item in Sharepoint list using javascript and Sharepoint web services


We can store insert items in Sharepoint items using many ways like using Sharepoint object model etc. But I need to insert items with Javascript.
I googled lot but didn't get any useful infomation, only Jan tielens' Blog has some infomation which showing list data on page using jQuery.
Finally I created the solution which stores the text box value in the Sharepoint list on button click. Following steps will show step by step information.
  • Create the blank web part page in your sharepoint site.
  • Browse this web part page
  • Edit page by clicking on site action -> Edit page
  • In any web part zone, click on 'Add a web part' then add 'Form Web part', Modify this web part.
  • Click on source editor button, it will open new window to add your content.
  • I added a HTML textarea and button with simple javascript which will store textarea value in given sharepoint list.
  • (Before that create new custom list with any name as you wish. I created with name 'Suggestions'
  • On source editor, copy and paste following code


  • 
    

    <script type="text/javascript">
        function addSuggestion(SuggestionText) {
            var xmldoc;
            var batch;
            var FeedbackHTTP;
            var ListName = 'Suggestions';


            //The batch variable builds up the XML that we are going to submit to the SharePoint list via the SharePoint web service
            batch = "<batch><method id="'1'" cmd="'New'"><field name="'Title'">" + SuggestionText + "</field></method></batch>";


            xmldoc = '<?xml version="1.0" encoding="utf-8"?><soap:envelope xsi="http://www.w3.org/2001/XMLSchema-instance" xsd="http://www.w3.org/2001/XMLSchema" soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:body><updatelistitems xmlns="http://schemas.microsoft.com/sharepoint/soap/">'
            xmldoc = xmldoc + '<listname>' + ListName + '</listname>';


            xmldoc = xmldoc + '<updates>' + batch + '</updates></updatelistitems></soap:Body></soap:Envelope>';


            FeedbackHTTP = new ActiveXObject("MSXML2.XMLHTTP.3.0");
            FeedbackHTTP.Open("POST", "http://YourSiteURL/_vti_bin/Lists.asmx?op=UpdateListItems", true);
            FeedbackHTTP.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
            FeedbackHTTP.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/sharepoint/soap/UpdateListItems");


            FeedbackHTTP.Send(xmldoc);


            alert("Thank you! your suggestion has been submitted successfully.");
        }
    </script>
    <textarea cols="15" id="txtSuggetion" rows="6"></textarea>

    <input id="myButton" onclick="javascript:addSuggestion(txtSuggetion.value);txtSuggetion.value = '';" type="button" value="Submit" />




  • (Note: Change YourSiteURL with your site name)
  • click on save button.
  • this will give you text area, insert any comment in text area then click on Submit button.
  • Now check your 'Suggestions' list. New item store with textarea value as in title.

Saturday, 27 February 2010

Sharepoint Search Control: How to add “All Sites” option in Sharepoint search control?

Today I worked on small task; I need to implement “All Sites” option in search control drop downbox. By default it’s not available in search control dropdown.

Follow simple steps to add “All Sites” option in Sharepoint Search control:

1. Goto root site and click on Site Setting

2. Click on ‘Search Settings’ from Site Collection Administration section

3. Second radio button option is selected for first time with name as ‘Do not use custom scopes. Display results in the search results page (/_layouts/osssearchresults.aspx).’ This option is for “This Site:” option

4. First radio button option is “Use custom scopes. Display richer results using the following Search Center:” This option is for custom drop down items like "All sites" and “people” options.

5. So to display “All Sites” option, we need to have “Search Center” team site. This Search Center team site is automatically created within enterprise sharepoint edition; but if you don’t have enterprise version then you need to create Search Center site

6. So create new team site by going to root site, select Site Actions -> Create Site , give search site name, URL name like e.g. Search, and select template as Click on Enterprise tab and click on ‘Search Center With Tabs’ option. Next click on Create button. It will create new Search Center site.

7. Once you create this site, copy URL of search site and paste into first radio option text box (as explained in step 4) in search setting option. (e.g. /Search/Pages), click on OK button

8. After that it will give new extra options “All sites” and “People” in search dropdown control.

Search anything with “All sites” option, it will return result in http://[your_site_name]/_layouts/osssearchresults.aspx page.



.

Thursday, 11 February 2010

Silverlight: How to change color style for progress bar?



In silverlight we can use progress bar control, but it's default template is with little light colors.



in this progress control use forground = "Red" but in this control this color look very lighter than original. So what to do if we want to use original solid html colors?

I tried with different methods like using



1. MyAverageBar.Foreground = new SolidColorBrush(Colors.Red);

2.
MyAverageBar.Foreground = new SolidColorBrush(Color.FromArgb(255,255,0,0));

but actually its styling problem.

How to change default Style of progress bar?

I changed default style using Microsoft Expression Blend! (Blend is useful in those perpose means we can do this thing in Visual studio also but this is with long process... so blend is easier)

Follow the following steps:

  1. Open XAML file in Blend!
  2. Right click on your progress control bar and select Edit Template > Edit a Copy.
  3. It will open new window to allow to create style resource
  4. Change 'This document' option from 'Define In' section, click on dropdown and select progress bar control
  5. Click on OK
  6. Then again click on Progress bar control
  7. From properties window clickFill style in Brushes section, it will open new menu and then select 'Reset' menu.
  8. press Cntr+S (save xaml file)
With this style it will remove default color style



Now Progress bar control looks like above.. :)







Silverlight: How to use Timer Control?

MainPage.xmal:



In between control add following code,

<Grid x:Name="LayoutRoot">

<TextBlock Loaded="StartTimer" x:Name="myTextBlock" />

Grid>

Right click on "StartTimer" and select 'Navigate to Event Handler', it will create new event handler method in .cs file. Add following code in xmal.cs file:



MainPage.xmal.cs:

private void StartTimer(object sender, RoutedEventArgs e)

{

System.Windows.Threading.DispatcherTimer newDispatcherTimer = new System.Windows.Threading.DispatcherTimer();

newDispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 1000); // for 1 seconds

newDispatcherTimer.Tick += new EventHandler(Every_Seconds);

newDispatcherTimer.Start();

}

int iCounter = 0;

// Retrive after every 1000 millseconds(1seconds) while the DispatcherTimer is active.

public void Every_Seconds(object o, EventArgs sender)

{

myTextBlock.Text = "Second Counter : " + (iCounter++).ToString();

}



Hope this will clear timer concepts in Silverlight!!!