About Me

I am a Software Engineer presently working in Microsoft as vendor.The main aim of this blog is to Share my knowledge in Sharepoint,AZURE and Silverlight.

Thursday, 28 August 2008

Getting new Tab instead of Development for our Custom Site Definition.

Hi ,

we have a custom site definition and one of the requirement is user should be able to see a seperate Tab for our Project rather than displaying the template under Development. for this we have 2 options.

1)if we are generating a sitedefintion using sharepoint solution Generator then open the solution and right click on project properties and select the “SharePoint Solution” tab.
Expand the Solution->Sitedefintion->Manifest.
give the Appropriate value in the Display Category as I gave “Sasi”.


2)if the solution is already deployed and you want to change then follow the steps.

Go to the folder in the SharePoint server:
C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\1033\XML


Open the xml webtemp file of ur definition.


You will see the following xml :
<-Templates xmlns:ows="Microsoft SharePoint">
<-Template Name="ABC_Site_Definition_11eec25f-6951-462a-a8e5-63d5ae20211e" ID="10000" >
<-Configuration ID="1" Title="ABC_Site_Definition" Description="" Hidden="False" ImageUrl="/_layouts/images/stsprev.png" DisplayCategory="ABC" />
<-/Template>
<-/Templates>
(Remove '-' in the tags)
Change the display category to your project name. This gives the tab as per your requirement.

Hidden=”True” Solves the other requirement it hides the other sitedefinitions which you not required.

So the Output u see as below.


Cheers give a try.

Sunday, 27 July 2008

Sending Mail in Sharepoint using code.

we should include the following namespace
for this Add reference of Microsoft.Sharepoint in references.

using Microsoft.SharePoint.Utilities;

Get the header information which contains To,Subject,CC...

System.Collections.Specialized.StringDictionary headers = new System.Collections.Specialized.StringDictionary();
headers["To"] = v-sasikp@microsoft.com;
headers["Subject"] = "This is test mail";


finally,
SPUtility.SendEmail(myweb, headers, emailMsg, false);

But this requires configuration of email server in central administration.

Simple Ex:
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;

namespace blogmail
{
class Program
{
static void Main(string[] args)
{
SPSite Site = new SPSite("http://sasikp-v:4008/");
SPWeb myweb = Site.OpenWeb();
SPUtility.SendEmail(myweb, false, false,"v-sasikp@microsoft.com", "This is test mail for blog","Pls dont reply to this mail this is testmail. ", false);

}
}
}

Thursday, 10 July 2008

How to Read Url value.

Yesterday i m working on Url column of a list. My code has to read the Url value rather than Url.

and i wrote code simply like below.
foreach(Splistitem item in Allitems)
{
string urlvalue= item["Link"].tostring();
.......
}
as link is my column and item is splist item.

The above urlvalue is giving a url value which is converted to string.

to solve this i used SpFieldUrlValue.

SPFieldUrlValue linkField = new SPFieldUrlValue(item["Link"].tostring());
string linkname = linkField.Description;

Cheers i got the value finally.

Thursday, 3 July 2008

How Dates Played with me.

1)Last night i was writing some code for my project and my requirement is to pull some data from the list based on some condition and condition is linked with some date field.

And i thought of using U2U tool which makes my life happy. But U2U is working fine, when i copied the query into my code its not working :( .

So rather than depending on U2U i went with CAML Language and Dates. I came to know that CAML Language recognises dates which is in "yyyy-MM-ddTHH:mm:ssZ" this format.

So lets coming to my code i have one date field in my list where i have to filter the list items based on the condition and condition is
" If the list fields date is less than Today-24 hrs " then get the items.

here i m deleting one day from today.
so the code i written is

DateTime today;
today = DateTime.Now;
Int32 DurationArtworkWFHrs = 24;
TimeSpan s = new TimeSpan(DurationArtworkWFHrs, 0, 0);
DateTime result = today.Subtract(s);
string date = result.ToString("yyyy-MM-ddTHH:mm:ssZ");

And my CAML Query looks like below :

SPQuery query = new SPQuery();
query.Query = "<-Where><-And><-Eq><-FieldRef Name='Status' /><-Value Type='Choice'>In Progress<-/Value><-/Eq><-Lt><-FieldRef Name='ProjectedEndDate' /><-Value Type='DateTime'>" +date+ "<-/Lt><-/And><-/Where>";

(Remove "-" from the above tags to get it worked).

SPListItemCollection myItems = mylist.GetItems(query);
int Projectcount = myItems.Count;

In the above code myitems collection gives the items i required. The variable date contains the converted string which our CAML Language understands. :)

2)One more Date Played with me in infopath form.

my requirement is i have to capture the date and it should be appended to the infopath form when it is submitted.

So for this i created one field in infopath form called "Millisec" .

and assigned our custom date format to this field.

XPathNavigator xnDoc = this.MainDataSource.CreateNavigator();
XPathNavigator fldMilliseconds;
fldMilliseconds = xnDoc.SelectSingleNode("/my:myFields/my:Millisec", this.NamespaceManager);
DateTime dd;
dd = DateTime.Now;
//string[] s = dd.GetDateTimeFormats();
//string date = s[105].ToString();
//date = date.Replace(":", ""); This works but we are capturing 135 elements into arraywhich is not required.
string date = dd.ToString("yyyy-MM-ddTHHmmss");
int TimeMilli = dd.Millisecond;
string instancename = date + TimeMilli;
fldMilliseconds.SetValue(instancename);

and while submitting the form append the value in the field. :)

Monday, 23 June 2008

How to Increase Performance of Sharepoint in all levels.

Tune your Sharepoint with following tips.Here are the tips given by me to our project Artcore.
Today i m going to blog how to increase the performance of our sharepoint portal in all the levels.
Performance of an application using MOSS framework can be increased by enhancing in either one or in all of the following areas.
1.0 Infrastructure.
2.0 IIS.
3.0 SharePoint portal.
4.0 Application.
5.0 Code Level

1.0 Infrastructure
SharePoint is an application that works best when it gets lots of memory and CPU resources. SharePoint’s Web role uses stateless connections. Using this as advantage, if we install the Web role on several servers, it is possible to divide the client load between them. However, for this we need to consider and solve two challenges first. One is to make sure all web servers have access to the same information which is done by using a common back-end database for all of them. The second thing to solve is that all of these web servers must look like one single SharePoint server which is done by using (NLB). SharePoint supports up to eight servers running the web service role.
1.1 Index server
Different activities in SharePoint require different extent of resources; for example, displaying a project Site normally generates a very light load on the server, whereas indexing the database generates much higher load.

The Index service including the crawling activity is very resource intensive regarding CPU and disk access. By separating this service from the Web, many more users will be supported in the SharePoint environment. The indexing activity can be split between up to four different SharePoint servers.
Note: Only one Index server can crawl on a given content source. If one index server goes down, no other server will take over the indexing crawling that server is configured to do.

With below topology we can double the performance, availability….,

Picture to be placed here.

1.2 Calculating the Number of Operations per Second (OPS) required
For computation of the load or the OPS, on the SharePoint server, the following formula is used

(http://blogs.technet.com/wbaer/archive/2007/07/06/requests-per-second-required-for-sharepoint-products-and-technologies.aspx)


A*B*C*D /360,000*E= OPS
Where,
❑ A = The number of users.
❑ B = The percentage of active users on a typical day.
❑ C = The number of operations per active user per day.(1-10)
❑ D = The peak factor.(1-10)
❑ E = The number of working hours per day.

For ArtCore

A= ~ 1000
B= ~ 100
C=~10
D= ~10
E= 12

1000*100*10*10/360,000*12=10000000/4320000 = 2.31 OPS.

By Redesign we can manage up to 20,000-40,000 of users.

1.3 Requests per second
The general rule is to plan for 1 Rps. While a small server farm serves about 60 RPS for 1000 users, a medium farm with 2 WFE servers can serve about 120 Rps.

1.4 Disk Space Needed
When planning for the required disk space, there is no need to worry about the SPS binary files, because they are small compared to other files. More important are the index and database files. Regardless of the database type, you still need to follow this important rule:

You must always have at least 50 percent free space on your database disk!
The reason for this is that some database troubleshooting utilities need to make a copy of the database to perform their tasks. If you don’t have the required space, you may get into a situation where you cannot fix a problem.



2.0 IIS
2.1


When creating a Web Application (and associated site collection) that the default is that a unique IIS application pool be used for each. This can have several benefits – should some unexpected error in a site cause a problem it will be localized to that site collection, additionally the worker process will be caching content related to those specific sites. Worker process sizes between 250-300MB on X86 WFE servers, and between 400-500MB on X64 WFE servers. There are also other application pools and related IIS processes to support Central Administration, SSP, and so on, on the various WFE servers. The best-practice approach will be to consider which Web Applications should share an application pool, and which should be unique. Using multiple application pools can be beneficial, but it is easy to over-do by always taking the default settings (use new pool). Each related process has to load an instance of the .NET runtime in memory, so un-needed (excessive) application pools can waste memory.

2.2
IIS Compression

HTTP Compression is a wonderful technology that accomplishes a lot of different things. It allows faster page serving to clients and lower server costs due to lowered bandwidth (these two being enough for me to implement).

HTTP Compression is when a Web server receives a request for a file and instead of just serving the file to the client, it checks to see if the client browser (or application) is "Compression Enabled". If so, the Web server does a check on what type of file is being requested (this is determined by the file’s extension). If the file is marked as a static file, such as an HTML file, IIS will check the Compression Cache Temporary Directory.

If a compressed version isn’t found, IIS will send an uncompressed version of the file to the client and a compressed version is placed in the temporary directory (IIS will only serve to the client from the temp directory). If the compressed version is found, IIS will send the file directly to the requesting client. If the requested file is a dynamic file, such as an ASP.NET Web form, then the response is dynamically compressed and sent to the requesting client (no temp directory access is ever done).

By running the below scripts we can achieve compression
cscript.exe adsutil.vbs set W3Svc/Filters/Compression/GZIP/HcScriptFileExtensions "asp" "dll" "exe" "aspx" "asmx" "ashx"
cscript.exe adsutil.vbs set W3Svc/Filters/Compression/DEFLATE/HcScriptFileExtensions "asp" "dll" "exe" "aspx" "asmx"
cscript.exe adsutil.vbs set W3Svc/Filters/Compression/GZIP/HcDynamicCompressionLevel "9"
cscript.exe adsutil.vbs set W3Svc/Filters/Compression/DEFLATE/HcDynamicCompressionLevel "9"

(http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/d52ff289-94d3-4085-bc4e-24eb4f312e0e.mspx?mfr=true)
3. 0 SharePoint level
3.1 Caching
SharePoint provides two types of caching.

3.1.1 Page output caching

3.1.2 Disk caching

Disk-based cache scheme can be enabled on a per-site basis, and should be set consistently on each WFE server. In a typical site there are likely several references to image files (BMP, JPG, and so on) or to CSS style sheets or JS script files. These can be cached to avoid repeated database access for what are essentially static objects, and thus improve page response times. The cache is disabled by default, and is enabled by editing a line in the site WEB.CONFIG file found in the IIS Inetpub folder structure related to the site on the server’s system disk. Edit the file and search for the second instance of “BLOB” to get to the right line, which looks like:

<(BlobCache location="E:\blobCache" path="\.(gif|jpg|png|css|js)$" maxSize="100" max-age="86400" enabled="false" )/>

Currently in production it is set to “false”.
The maxSize parameter is the maximum size of the disk cache in GB.
4.0 Application level
Our Project’s Key strength is InfoPath forms.
InfoPath Forms Services uses session state to store the large amount of transient data generated while filling out a form. As a result, front-end Web servers can remain stateless between round trips, and each post back is not burdened with carrying large amounts of session state information over narrow bandwidth pipes.

So if you are using infopath forms use formview state rather than session state.

5.0 Code Level
Many times we will delete or update list items in the lists by using Object oreiented code if these operations or doing on lists having bulk items then use
"ProcessBatchData" we can increase performance very much.

http://msdn.microsoft.com/en-us/library/cc404818.aspx

Advantages:
1) Performance
2) High availability(WFE & DB)
3) High Throughput
4) Scalability
5) No downtime

Saturday, 14 June 2008

How to Integrate Silverlight in Smartpart.

can we integrate our smartpart with silverlight.(I say YES.)

People who are working with smartpart is in dilemma. how to use silverlight in smartparts then here is the solution jump and give a try.

This Post is continuation of my previous post so go through my previous post for creating silverlight webpart.

People who worked in asp.net feels uncomfort in sharepoint as we have to develop custom webpart from the scratch for them smart part is a good webpart which takes usercontrol and renders our usercontrol to webpart.
you will found the smart part in the below link.
http://www.codeplex.com/smartpart/Release/ProjectReleases.aspx?ReleaseId=10697

The latest release for smart part is v1.3. it is a good webpart developed by inheriting sharepoint webpart.This supports ajax also.

Now the Question is can we integrate our smartpart with silverlight.

I tried in multiple ways but i got succeded in Following way. (as usercontrol is .net controls we have to render our controls on top of the silverlight content)

To integrate Smart part and silverlight the procedure we have to follow is:
1) Create a web part with silverlight rendering.(silverlight web part)
2) Overlap Smart part on the silverlight web part.


Open the User Control and place your code in the div tag.

<-div style="position:absolute; width: 600px; height: 100px; z-index: 1; left: 24px; top: 95px" id="layer1">
This makes the control to Render at our required position. We can adjust the properties as per our requirement.

My user control looks like below in design mode.(Just adding two numbers)



Output of the user control after rendering on silverlight web part in my SharePoint site.
Output in the IE Browser.(As this differs very little in mozilla).



Cheers it worked for me i have some more options
1)rendering directly silverlight content in usercontrol it worked for me if it is .net application but it is not working for sharepoint i may miss some thing ill try soon and update.
2)inheriting the smartpart webpart and adding our code in Onprerendermethod and override rendermethod.(didnt gave a try.)

now you can give a try with this. :)

How to Create a Silverlight Webpart.

Most of the people ask me how to integrate silverlight in sharepoint. In my previous post I explained about rendering silverlight content in a sharepoint page.

This time i'll explain you how we can render silverlight content in a sharepoint webpart where we can display individual silverlight content in a webpart rather than rendering silverlight for total Sharepointpage.

Here are the Steps for creating silverlight web part.
1) Open visual studio and create a new project by selecting web part template. As shown in the below figure.


2) Add the Silverlight files Scene.js, Scene.xaml, Silverlight.js to the project as shown below.

After adding the silverlight files to the project set the “Build Action” property of each file to “Embedded Resource”.


3) We added silverlight files in to the assembly by making the property to “embedded resource”. To expose the file to a web request we need to add the following code in .cs file .These entries expose the embedded resource to the “ Client Script Manager” can get the file and know what kind of file it is.
[assembly: WebResource("Otherswebpart.Silverlight.js", "text/javascript")]
[assembly: WebResource("Otherswebpart.Scene.js", "text/javascript")]
[assembly: WebResource("Otherswebpart.Scene.xaml", "text/xml")]
The code in my .cs file. I took Otherswebpart as my name space. We have to add assembly level information just above the name space as shown in the figure.

4) We said to the assembly by the above lines now we have to register the script files to the page before the files are used. So we need to add the following lines of code in the method called “OnPreRender”.
My method in the .cs file has the following code.
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);


this.Page.ClientScript.RegisterClientScriptResource(GetType(), "Otherswebpart.Silverlight.js");
this.Page.ClientScript.RegisterClientScriptResource(GetType(), "Otherswebpart.Scene.js");

}

The above code explains registering of my script files to the page before rendering.

5) Finally we have to render the Silverlight content. So I added the code which we found in the default.html.js file. The reason I wrote the every line of default.html.js file instead of calling “CreateSilverlight()” method is we require the source of the ” page.xaml” which is embedded in the assembly.

So my render method looks like the following.




A) The text which is in yellow colour describes the source of our “Scene.xaml” file.
B) The property isWindowless:’True’ allows us to overlap our .net controls on to the silverlight content. (Add this property it doesn’t come by default.)

6) Finally we have to build and run the project.
Before that we have to set one more property. Go to the project properties and select the debug tab and set the property “start browser with URL” to your SharePoint site as shown in the below figure.


By doing this we should be able to see the output of the web part in our SharePoint site.
Check the Output in my site which is having “Otherswebpart webpart” which is having silverlight content and with one silverlight button.



Cheers Now Give a try with this. in my next post i'll explain how to integrate silverlight webpart with smartpart.