Wednesday, May 30, 2012

Enable SessionState in Sharepoint

1) Open SharePoint 2010 Management Shell (As Administrator) and type the following command:

Enable-SPSessionStateService –DefaultProvision.

2) To resolve the error and to enable session state for SharePoint there are two entries that need to exist in the web.config file.

The first is to ensure that enableSessionState is set to TRUE.

...<..pages enableSessionState="true" enableViewState="true" enableViewStateMac="true" validateRequest="false" pageParserFilterType="Microsoft.SharePoint.ApplicationRuntime.SPPageParserFilter, Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" asyncTimeout="7"..>..

The second is to ensure that the remove and add lines exist in the modules section for Session.

..<..modules runAllManagedModulesForAllRequests="true"..>.. …
.<.remove name="Session" ./>. .<.add name="Session" type="System.Web.SessionState.SessionStateModule" preCondition="" ./>. … modules>

ALSO,Additional steps to ensure the "web.config"
1.Add to the configuration/system.webServer/modules element.
2.Set the enableSessionState attribute of the configuration/system.web/pages element to true.
3.Add to the configuration/system.web element


3) Reset IIS.

Enable Diagnostics in WCF service

Add these entries to the web.config file of the WCF service site(application) in question.




Consume the service. After the operation is complete or errors out, open the log file at the above specified location on the machine hosting the service to see the issue.

]] Comment this section when not in use to make sure it does not affect performance.

Also, make sure you set the includeExceptionDetailInFaults attribute to true in the WCF config file to see the root error. ​

Javascript Error

http://sympmarc.com/2010/08/28/how-to-fix-sys-argumenttypeexception-object-of-type-sys-_application-cannot-be-converted-to-type-sys-_application-error/​

Microsoft JScript runtime error: Object expected

It turns out I was missing a curly brace in Javascript. This post saved me lots of time. http://social.msdn.microsoft.com/Forums/en-US/netfxjscript/thread/eede0ba6-1e1d-4248-98bb-6383839dfac7/​

Raising Javascript Event in ASP.NET user control

Raising Javascript Event in ASP.NET user control http://stackoverflow.com/questions/389450/raising-javascript-events-in-asp-net-user-control Server Side Method() { Server side code... this.Controls.Add(new LiteralControl("")); } This will execute the server side code​ and print the document next. We can even call this at the beginning/end of Page_load or after some server code is executed.

WCF Service Troubleshooting

WCF Service Troubleshooting tips

http://www.infosysblogs.com/microoft/2009/06/troubleshooting_wcf_service_ap.html ​

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

http://stackoverflow.com/questions/399847/net-memory-profiling-tools

Thursday, March 29, 2012

Assigning Guids to variables in C#

Assigning Guids to variables in C#

Guid invt_id = new Guid("abcd-efg-etc.....Any Guid String");
Guid invt_id = Guid.Empty;

Wednesday, March 14, 2012

Preventing GridView from reacting to enter button

function disableEnterKey(e)
{
if(e.keyCode == 13)
e.returnValue=false;
e.Cancel=true;
}



asp:GridView ID="grdView1" runat="server"
onkeydown="javascript:disableEnterKey(window.event);"


http://stackoverflow.com/questions/152099/i-want-to-prevent-asp-net-gridview-from-reacting-to-the-enter-button1​

Making a TextBox ReadOnly

Making a TextBox ReadOnly

asp:textbox id="txtItemTotal_Edit" class="TextBoxReadOnlyStyle" text="abcd" enabled="false" enableviewstate="true">' runat="server"> /asp:textbox


If you want your TextBox to behave like a label but need the values retained during a postback i.e, in ViewState then using Enabled="false" and EnableViewState="true" attributes, is one way to do it. You can apply any desirable style to your textbox using css.

Enable Diagnostics on Sharepoint Server

To Get IIS Logs:

1.Go to IISManager->Sites->Look at Site InQuestion->Note the ID of the site.
2.Click on the Site->Feature View->Logging->Note the Directory Path
3.Run your issue.
4.Browse to the Logging Directory and locate the File that ends with the ID of the site and grab It.
To Enable Diagnostics on Sharepoint Server:

1.Go to Central Admin->Monitoring->Reporting->Configure Diagnostic Logging
2.Select All Categories, Set the level to Verbose; and note the Log Path
3.Go to Servics.msc and Restart Sharepoint 2010 Tracing service
4.Run your issue
5.Browse to the log file path and locate your needed log file.
To disable Diagnostics on the server:(Run this in Powershell)

stsadm -o setlogginglevel -default

Enable Scripting on your browser

To allow all Web sites in the Internet zone to run scripts, use the steps that apply to your browser:


Windows Internet Explorer
(all versions except Pocket Internet Explorer)



Note To allow scripting on this Web site only, and to leave scripting disabled in the Internet zone, add this Web site to the Trusted sites zone.

1.On the Tools menu, click Internet Options, and then click the Security tab.
2.Click the Internet zone.
3.If you do not have to customize your Internet security settings, click Default Level. Then do step 4
If you have to customize your Internet security settings, follow these steps:
a. Click Custom Level.
b. In the Security Settings – Internet Zone dialog box, click Enable for Active Scripting in the Scripting section.
4.Click the Back button to return to the previous page, and then click the Refresh button to run scripts.
Got this from http://support.microsoft.com/gp/howtoscript

​

Get Sharepoint List GUID from Browser

Go to Information Management section in the List Settings and the URL will have the decoded list GUID.

SharePoint Exception: No item exists [url]. It may have been deleted or renamed by another user

By changing the querystring key from id to someother key named like "sid" or "pid" or anything other than "id" made the error go away.

Signing an assembly

http://msdn.microsoft.com/en-us/library/6f05ezxy(v=VS.71).aspx



To create a key pair
•At the command prompt, type the following command:
sn –k
In this command, file name is the name of the output file containing the key pair.
The following example creates a key pair called sgKey.snk.

Copy
sn -k sgKey.snk
If you are using an IDE, such as Visual Studio .NET, to sign an assembly with a strong name, you must understand where the IDE looks for the key file.
For example, Visual Basic .NET looks for the key file in the directory containing the Visual Studio Solution, whereas the C# compiler looks for the key file
in the directory containing the binary. Put the key file in the appropriate project directory and set the file attribute as follows:

VB

[C#][assembly: AssemblyKeyFileAttribute(@"..\..\key.snk")]

Thursday, February 16, 2012

Calling Javscript from code-behind

We can call javascript alert messages from code-behind(on say button_click event etc..) as below:

//Display success message (several ways) shown here
//Method 1
string st = "script language='javascript'" + "window.alert('CustomerId' :" + CustId + " deleted successfully)" + "/script";
Page.ClientScript.RegisterClientScriptBlock(GetType(),"del_successMessage", st, false);


//Method 2
//Here the Javascript function is written normally in the script tag in the Head section of the HTML page.
Page.ClientScript.RegisterStartupScript(GetType(),"Javascript", "javascript: fnShowSuccessMessage();",true);


//Both the above methods do not work if we use Update Panel as a container..see solution that works below.

System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append(@"script language='javascript'");
sb.Append(@"alert('CustomerId :" + CustId + " deleted successfully');");
sb.Append(@"/script");
ScriptManager.RegisterStartupScript(btnDelete, GetType(), "MyJavaScript", sb.ToString(), false);
I had to remove tags on the script tag in order to post it.

To Check if the dropdownlist has a given value before selecting it

To Check if the dropdownlist has a given value before selecting it:

ListItem li = ddlItems.Items.FindByValue(MyNr.ToString());
if (li != null) //Item Found in dropdown..so select it and display details
{
//Value was found
}
else
{ //not found }

Monday, June 30, 2008

Business Data Catalog

Business Data Catalog.

Recently, I had to evaluate and implement the Business Data Catalog(in Sharepoint). I found it to be very useful. The following article by Sahil was very useful during my learning phase.

Getting Started with Business Data Catalog.

The BDC Editor tool available with MOSS SDK was useful in getting me started, but later, I edited the Application Definition XML file manually. This proved to be easier than the editor for me.

Tuesday, April 08, 2008

Locating Contributor settings inside Sharepoint Designer



Locating Contributor Settings inside Sharepoint Designer

Friday, March 07, 2008



HOW TO DEPLOY A WEBPART THAT HOSTS A WEB USER CONTROL TO SHAREPOINT

There are a couple of different ways to create the web part and deploy it to Sharepoint, but here is how I did it. In my case, I developed locally on my machine( I did copy the Sharepoint dlls locally for reference). The deployment server was on a virtual machine where I had MOSS setup.

1. Create the Web User Control(with code behind) in Visual Studio.

2. Sign the Assembly so that it has a strong name

3. Create the web part (either Sharepoint Webpart or ASPNET Webpart) in Visual Studio. Another good article for reference

4. Sign the Assembly.

5. Go to the Sharepoint Deployment Server.

6. Copy both the above strong named Assemblies(user control and webpart assemblies) to GAC on the Sharepoint server

7. Modify security settings of Sharepoint site by changing the Trust to Full in Web.Config of the Sharepoint Site like this..
trust level="Full" originUrl="" />

8. Add Safe Control Entries to the DLLs added to GAC in Web.Config of the Sharepoint Site similar to this.. ( I used Reflector to get the strong name)
SafeControl Assembly="SmartParticles, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=70d581d0b6a14330" Namespace="WebParticle" TypeName="*"
Safe="True" />
( I used Reflector to get the strong name)

9. Add an Assembly element to the assemblies section of Sharepoint site’s web.config file..similar to this.

assemblies><

add assembly="SmartParticles, Version=1.0.0.0,
Culture=neutral,
PublicKeyToken=70d581d0b6a14330"
/>

>
>


10. Create a Folder usercontrols under the Sharepoint site ex: wss/VirtualDirectories/80/usercontrols. Make sure this is not an application in IIS, as otherwise, it will fail.

11. Copy the ascx file(web user control file) and the other css files, xslt files and images(used by the user control) to this usercontrols folder. Make sure that when you access these other files from inside your user control code, they are referenced as “/usercontrols/*.gif” and so on.

How to populate the Web Part Gallery with the added Webpart.
The user needs to be the administrator of the site in order to do this.

Open the main Sharepoint site and go to Site Actions->Site Settings->Modify All Site Settings and click Webparts under Galleries.

Click New..this will by using Reflection populate the new webpart from the safe controls list in web.config.

Select the new web part and click “Populate Gallery” to place it in the gallery.

The webpart is now availableto populate on any of the Webpart pages inside Sharepoint.

See the webpart from my Test Sharepoint Site below:

Tuesday, February 12, 2008

Designing Reports with Reporting Services

The following blog has a good post on how to setup Reporting Services Add-in
http://blogs.threewill.com/implementingsharepoint/Lists/Categories/Category.aspx?Name=Reporting

Issue 1:

As I was working with designing reports, I had a scenario where I had to have a parameter with a dropdown of all the Locations that a user has access to. This is stored in SQL Server in my case. I was not sure how to do it. I knew I had to create a dataset that returns the locations and pass in the logged user. I did do that, but instead of passing User!UserID, I created another Report parameter called UserID and set that to User!UserID and passed this ReportParameter as the Dataset’s Query Parameter.

When I tried to do it like that, I ran in to an error. I searched for it and found the solution to the problem in the blog entry below. I had the Dataset Report Parameter declared above the UserID parameter. Fixing it as below, made the error go away.

Declare Parameter Y before X as below.
Go to the Layout tab
Select the Report object in the properties window
Go to the ReportParameters property and edit
Move Y above X using the arrows
http://blogs.infosupport.com/raimondb/archive/2006/08/09/sqlrepparamerror.aspx

Issue 2:

I had a need to conditionally sum the underlying data and display it in the group footer.
I followed the following advice from a forum and it worked.

Ex:=Sum(iif(Fields!Status.value = "Value a", Cdbl(Fields!Payment.Value), 0.0))

http://www.tek-tips.com/viewthread.cfm?qid=1072925&page=3


Issue 3:

I was trying to solve a problem by using an aggregate function and display it in the footer by using another aggregate function. It won’t work in Reporting Services as you cannot embed aggregate functions within each other, nor can you use a calculated field as an expression in an aggregation function.

I even considered using the technique below, but did not help.

http://www.codeprof.com/dev-archive/211/19-82-2111320.shtm

I finally solved my problem by using a Report Parameter instead.