I had a sitution to stream a file from SQL Server.
ASP.Net LinkButton was used in the ITemplate to use in GridView and Click event was defined with statements like
response.AddHeader("Content-Disposition", "attachment; filename=" + fileName );
response.AddHeader("Content-Length", blob.Length.ToString());
response.ContentType = "Application/x-msexcel";
response.BinaryWrite(blob);
Everything was working perfect in WebApplication. When the webpart was deployed to SharePoint, the server side click event fired only once. After that the link became irresponsive. If the page is refreshed, the link worked once again for 1st time.
After several googling, found that SharePoint stores time-stamp on client side for security reasons and avoids multiple post-backs for the same control.
There are 2 ways to over-come this issue. Just add an appropriate line as below
1. Generic way
imageButton.OnClientClick = "this.form.onsubmit = function() {return true;}";
or
hyperLink.OnClientClick = "this.form.onsubmit = function() {return true;}";
or
linkButton.OnClientClick = "document.getElementsByTagName(\'form\')[0].onsubmit = function() {return true;}";
2.Specific to SharePoint
linkButton.OnClientClick = "_spFormOnSubmitCalled = false;_spSuppressFormOnSubmitWrapper=true;";
After adding single line (one of the above), the webpart worked like a charm.
This blog is for development tips and tricks mainly on .NET and SharePoint development which could save time of someone like me.
Tuesday, 22 December 2009
LinkButton in SharePoint - Not firing Click Event
Wednesday, 14 October 2009
Composit Control Tips
http://skysigal.xact-solutions.com/Articles/tabid/434/ctl/ArticleView/mid/1024/articleId/36/Default.aspx
Friday, 18 September 2009
Read RSS and Atom feed in C#
I remember we had to go for separate framework to read the feeds and parse it. In that case we need to refer the framework in our project and install that assembly in Bin or GAC.
Now with .Net 3.5, life has become much easier.
Yes, with the namespace 'System.ServiceModel.Syndication' it is just few lines of code to read and parse the feeds either RSS or Atom.
Just add reference to 'System.ServiceModel.Web' to your project and include above namespace in your class, thats it.
Below is the code i used.
XmlReader reader = XmlReader.Create(curUrl);
SyndicationFeed feed = SyndicationFeed.Load(reader);
string title = String.Empty;
string link = String.Emplty;
DateTime dateTime = null;
foreach (var feeditem in feed.Items)
{
title = feeditem.Title.Text;
dateTime = feeditem.PublishDate.LocalDateTime;
link = feeditem.Links[feeditem.Links.Count -1].Uri.OriginalString;
//Do your tasks here
}
Easy to deploy and maintain too.
Happy Coding
வாழ்க வளமுடன் :)
Useful SharePoint Links
Accessing Data from Workflow Association and Initiation Forms in Windows SharePoint Services 3.0
Best Practices: Common Coding Issues When Using the SharePoint Object Model
Best Practices: Using Disposable Windows SharePoint Services Objects
Checklist for Creating SharePoint Web Parts
Creating Custom Timer Jobs in Windows SharePoint Services 3.0
Creating a Windows SharePoint Services 3.0 Custom Field by Using the EntityPicker
Creating a Windows SharePoint Services 3.0 Web Part Using Visual Studio 2005 Extensions
Development Tools and Techniques for Working with Code in Windows SharePoint Services 3.0 (Part 1 of 2)
Development Tools and Techniques for Working with Code in Windows SharePoint Services 3.0 (Part 2 of 2)
Securing Application Pages in Windows SharePoint Services 3.0
Selective Content Migration in Windows SharePoint Services 3.0
Understanding and Creating Customized and Uncustomized Files in Windows SharePoint Services 3.0
Understanding the Administrative Object Model of Windows SharePoint Services 3.0
Usage Event Logging in Windows SharePoint Services 3.0
Using Solution Packages to Deploy Features and Content in Windows SharePoint Services 3.0
Workflow Scalability and Performance in Windows SharePoint Services 3.0
Working with ASP.NET 2.0 Web Parts and Windows SharePoint Services 3.0
Wednesday, 22 July 2009
Building CAML Query
http://sharepointmagazine.net/technical/development/writing-caml-queries-for-retrieving-list-items-from-a-sharepoint-list
Thanks Boske.
Thursday, 18 December 2008
SharePoint Tools
1. SharePoint Tips Utility Pack - Developed by my ex-colleague Ishai.
This tool has many functions. Setting the properties of a field and managing Event Listeners were we largely used among them.
Mate, you are champion. I am really proud that I was your team member. You have answer for all SharePoint questions.
2. Stramit SharePoint 2007 Caml Viewer
This tool can be used to see the GUIDs of any lists and views very easily. Also all the fields and its internal names can be easily seen using this tool.
3. U2U CAML Query Builder
Last but not least, the most useful tool for building CAML queries to use in SharePoint object model coding.
Tuesday, 26 June 2007
"Trying to use SPWeb object that has been closed.." Error
We were getting “Trying to use an SPWeb object that has been closed or disposed and is no longer valid.” in our MOSS -Workflow project.
After investigating all the source codes, I found the error causing statement in WebPart class.
The best practice is to dispose objects either by calling Dispose() in finally block or with using clause.
The snippet causing problem in our project was
SPGroup group;
using (SPWeb web = SPContext.Current.Web)
{
group = web.Groups[“Administrators”];
this.DisplayText = "Submit for Approval";
:
:
}
Here, the object is not really created in the memory, only the reference to the exisiting object is got and used. We should not dispose the current context web object manually in our code.
More information about best practice can be found at
http://msdn2.microsoft.com/en-us/library/ms778813.aspx
Happy Coding :)