Which w3wp.exe process belongs to which App Pool in IIS6
While debugging webparts , event handlers etc. in sharepoint we may need to attach the w3wp.exe. But the real problem is that to identify which w3wp.exe is for the sharepoint webpage we are trying to debug?, there may be two more w3wp.exe processes. In that time we can attach the two w3wp.exe processes it will work. But it slow down the server performance.
Today I got a solution for this, Microsoft is providing some script files to identify which w3wp.exe process belongs to the sharepoint application pool.
To get the details Go to Command Prompt. Change directory to SystemRoot/System32. Use command cscript.exe iisapp.vbs. <enter> will give you all the application process, with the w3wp process Ids.
W3WP.exe PID: 3848 AppPoolId: SharePoint – 80
W3WP.exe PID: 6044 AppPoolId: SharePoint Central Administration v3
From my machine.
http://weblogs.asp.net/owscott/archive/2004/09/21/
Which-w3wp.exe-process-belongs-to-which-App-Pool-in-IIS6.aspx
SPUtility.SendEmail
In my project I need to send mail to Administrator, while adding items to a list using Webpart. I have tried ASP.Net, System.Net namespace but I need to read all the server and mail settings from any config file. After I got sharepoint’s own mechanism to send mail.
SPUtility.SendEmail(SPContext.Current.Site.OpenWeb(), false, false, "admin@myserver.com", "Hello World", "This is a Sample Mail");
This will send a mail to “admin@myserver.com”, with “Hello World” as subject and “This is a Sample Mail” as body. You can send HTML emails by changing the third parameter to TRUE.
Update : You may need to use SPSecurity.RunWithElevatedPrivileges method to send mails.
http://msdn2.microsoft.com/en-us/library/microsoft.sharepoint.spsecurity.runwithelevatedprivileges.aspx
This method enable users to Execute the specified method with Full Control rights even if the user does not otherwise have Full Control.
Sharepoint Rich Text box in Webparts
In my current project, I have to develop a webpart, in which users should able to Add / enter comments using Sharepoint native rich text box. I have tried, RichTextField, I am able to add it, but while rendering it is giving a lot of problems like, Control mode not set etc.
After some “google”ing I found some other control, the InputFormTextBox, using this, I am able to create a webpart, which uses sharepoint default Rich Text Editor.
InputFormTextBox txt = new InputFormTextBox();
txt.TextMode = TextBoxMode.MultiLine;
txt.RichText = true;
txt.RichTextMode = SPRichTextMode.Compatible;
And you can use txt.Text property to read the contents of the Textbox. I am adding / inserting the Text to a multiline column in a custom list.
Adding items to sharepoint list
Sometimes it is required to manage sharepoint lists using C# or webparts. The project, currently I am working requires the same. Add method is available for list(SPList), but there is no way how can I update or save it. After little “google”ing I found it.
SPListItem MyItem = currentList.Items.Add();
MyItem["myfield"] = "Hello World";
MyItem.Update();
Thats it, it will update myfield column with “Hello World”.
Code review
Last few days I was to code review one of our sharepoint projects. Actually there is nothing for review because almost all the pages are developed by MS Developers and only we are customizing it. But I have to do the job and it give me some good experiences.
Lessons learned from Code review.
- Always dispose objects, when you are not using it.
- Use string.Compare instead of using ToUpper() and “==” combination for string evaluation
- Avoid direct casting, instead of use “as” operator
- Try to use “using” code block, if the class implements “IDisposible” interface
- Always close Database connections, before disposing it.
Here is the few things I learned in the code review session.