Thursday, March 29, 2012
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
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
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
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
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
SharePoint Exception: No item exists [url]. It may have been deleted or renamed by another user
Signing an assembly
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
//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.
I had to remove tags on the script tag in order to post it.
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);
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
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
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..
SafeControl Assembly="SmartParticles, Version=1.0.0.0, Culture=neutral,( I used Reflector to get the strong name)
PublicKeyToken=70d581d0b6a14330" Namespace="WebParticle" TypeName="*"
Safe="True" />
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
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.
Tuesday, November 27, 2007
Here is a blog entry about this, which I found was useful.. I have'nt tried uninstalling it as mentioned here...but was good to know about it.
http://decipherinfosys.wordpress.com/2007/05/06/wss-and-sql-server-embedded-edition/
Related Forum entry that I found..
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=949426&SiteID=1
You can connect to the SQL Server Embedded Edition from Management Studio Express using the following as Server name..thanks to the above forum entry...
\\.\pipe\mssql$microsoft##ssee\sql\query
Tuesday, November 20, 2007
Tuesday, October 02, 2007
Service Pack 2
(Configuration Woes for Sharepoint Integrated Mode)
I finally got the SQL Server Reporting Services 2005 to run in Sharepoint Integrated Mode and can now see Reports.
Story:
We were evaluating Reporting Services and Sharepoint and wanted to see how well both of these technologies could help leverage our Business. So, tried to setup a Lab Environment. As I already mentioned in my previous blog entry, we had an Image of Windows Server 2003 SP2 and SQL Server 2005 SP2 with Reporting Services 2005 SP2 and MOSS 2007 loaded.
I started with this image and tried to set up the Integration Mode.
So, first downloaded the Reporting Services Addin here and installed it and configured the server per the documentation. I followed the links below:
http://technet.microsoft.com/en-us/library/aa905871.aspx
http://blogs.msdn.com/sharepoint/archive/2007/08/02/microsoft-sql-server-reporting-services-installation-and-configuration-guide-for-sharepoint-integration-mode.aspx
This second one above was extremely helpful when I went back and checked on some things that I overlooked the first time and configured later while I was troubleshooting below.
Issue 1
It appeared that the Addin installed fine, but when I went to look in the Central Administration, I could not find the Reporting Services Section under Application Management at all….what did I do wrong?
After some research, found out that if your Sharepoint Site Collection was not available or if the account you are using to install Reporting Services Addin does not have full control over that Site Collection(you are concerned about) when you install the Reporting Services Add-in, then the Reporting Services Integration Feature is not activated for that Site collection.
If you activate it, by doing the steps below for the site collection, you can see the Report Viewer webpart and also add Reporting Services Content Types.
http://blogs.msdn.com/rosettaue/archive/2007/04/06/how-to-activate-the-report-server-feature-in-sharepoint-central-administration.aspx
Okay…I uninstalled add-in and reinstalled with an account that was the Site Collection Adminitrator/Farm Administrator and Local Administrator of that machine. I could have done the above for my site collection in question and it would have worked.
After that I could see the Reporting Services section under Central administration. However, when I clicked on “Set Server Defaults” option is Central Administration, I was getting the following error:
Issue 2
An unexpected error occurred while connecting to the report server. Verify that the report server is available and configured for SharePoint integrated mode. --> Server was unable to process request. ---> The request failed with HTTP status 401: Unauthorized.
Looked all over internet and even posted the question to the forum. I followed the suggestions some people had in Brian Welckers Blog and couple others, but no luck.
I tried the following workarounds:
http://support.microsoft.com/kb/871179/en-us%20:%20Here%20I%20actually%20tried%20setting%20up%20my%20environment%20to%20“NTLM”%20(workaround)%20as%20I%20was%20working%20with%20an%20image%20and%20could%20not%20get%20the%20spn%20to%20work.: Here I actually tried setting up my environment to “NTLM” (workaround) as I was working with an image and could not get the spn to work.
http://stevenharman.net/blog/archive/2007/03/21/Avoiding-the-401-Unauthorized-Error-when-Using-the-ReportViewer-in.aspx: Here I even modified the registry, even though I was working with Windows Server 2003 SP2…which may not have needed this…
Issue 3
Well. I was tired of getting the above error message to go away and thought that as Set Server Defaults was just an optional requirement, I would go ahead and add the Report Viewer Web part to my Sharepoint Site. I was able to add the Report Viewer web part , but when I tried to create a shared data source or tried to choose an rdl to load the report viewer….I was getting an error
Well, I tried a couple more things….
I added SSRSWebAccount that I was using to run my Reporting Services Web Service (which also is my Report Server ApplicationPool account) to the Reporting Services Database (in my case the name of the database was OSS1) by going to the SQl Server Management Studio and manually assigning it. For some reason, it was not there to begin with.
I gave RSExec permission to SSRSWindows Account on Reporting Services database.
In Central Administration, I have Authentication Providers for my Site Collections set to Integrated Authentication..Kerberos…
In Central Administration, Reporting Services -> manage integration settings… I have the Authentication Mode set up to Trusted Account.
None of this helped and suddenly I looked at the Reporting Services’ Database Version and noticed that it was 9.0.0.33. I knew that SP2 version was 9.0.03042. The version that was loaded on that image was the December, 2006 pre release version
So, what does it hurt…so I went and grabbed the latest released version of SP2 9.0.03042 and applied it on my server. After that I went back and filled in any missing configuration that I applied above. Most of it was already there.
Okay….tried now going to Set Server Defaults,…yippe…it worked…
Both of my above issues went away after I installed SQL Server 2005 SP2 9.0.03042.
It was strange that I did not have to setup spn’s even though I have my Site Collections as Integrated…Kerberos as stated was required somewhere in the docs… I still don’t completely understand that inner workings of all this…but it works well now.
Remember, all the workarounds that I applied (as stated in Issue2 and Issue3) on the server still remain. I did not undo any of that…so all that with the SP2(3042) may be what helped me solve this….
Good Luck to those of you….on your journey to Configuring Reporting Services in Integrated Mode.
Wednesday, September 19, 2007
I am still having trouble getting Reporting Services to work in Sharepoint integrated mode. So, I decided to swap to native mode and try to display Reporting services Reports using WSS 2.0 Report Viewer and Report Explorer Web parts. All this I am doing in a test environment on an Image got from Microsoft, with MOSS 2007 and Reporting Services 2005 SP2 installed.
For this I followed the following article:
http://msdn2.microsoft.com/en-us/library/ms159772.aspx
However, when I tried to run the following, I was getting an error that said, it was already installed.
STSADM.EXE -o addwppack -filename "C:\ Program Files\Microsoft SQL Server\90\Tools\Reporting Services\ SharePoint\RSWebParts.cab" –globalinstall
But, I could not see the Report Viewer and Report Explorer Web parts in the “Add Web Parts” dialog box, when I tried to add them to my Sharepoint Site. I searched all over internet and found the following blog entry:
http://sqljunkies.com/WebLog/sqlbi/archive/2005/01/23/6802.aspx
I followed it and changed my STSADM command as below and ran it. In my case, as I had MOSS 2007 loaded on the same machine as Reporting Services SP2, the STSADM was found at: C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN. So, I changed to this directory in command window and ran the following command.
STSADM.EXE -o addwppack -filename "C:\ Program Files\Microsoft SQL Server\90\Tools\Reporting Services\SharePoint\RSWebParts.cab" –url
http://mysharepointsite/
And :) it worked that time. It said it installed fine. When I went back to add web parts, I could now see both the Report Viewer and Report Explorer Web parts. Next, I followed the first article above and setup the Report Manager Url and Report Name properties for the Report Viewer webpart and can see the Report
fine.
See image below:
Wednesday, September 05, 2007
Friday, August 17, 2007
We were successfully able to load MOSS 2007 on a production box and have couple of sites up and running. Everything was working till the other day, a user complained that he could not find "Connect to outlook" and other Office integration options in the menu when he chose Calendar view on the calendar. There was also no "Datasheet View" on the All Events view of the calendar list. See image below:

So, the solution was in Central Administration->Application Management->Authentication Providers--->Here there is an option to enable client integration. Enable this for the correct application and it works. The menus are now shown as expected.
Next, when I was testing the datasheet option, it wouldn't export but gave me an error stating that the wss Datasheet component was not correctly loaded....
Apparently, the problem was I did not have Office 2007 loaded on my client PC. The web datasheet option is only available if you have Access 2007 on your client machine. However, later I found the following article and followed it.
http://support.microsoft.com/kb/833714
I installed sharepoint support to my installed Office application as above and the datasheet option now works just fine.

