I had the problem of saving files which I uploaded programatically to Sharepoint list item. When I tried to save them, there's pop up dialog saying the file is in read only mode, even I had all the required permissions.
I had the problem of page not able to redirect when in an ajax postback. It happens to be the fact that I disabled a line in web.config:. This line should be added in HttpModules, so that redirection will work in Ajax postback. This class manages HttpModules for Ajax functionalities in ASP.NET.
A useful function to send email in Sharepoint, programatically.
This post shows you how to retrieve a checkboxlist from a multi choice field as well as how to update the field using SPFieldMultiChoiceValue.
Aaron was creating a custom web service to be used by web parts in Sharepoint, but then there was a problem of a giant list of "undefined" values returning. Done a lot of research and later this brilliant post directed us to the right place.
I wanted to use Ajax control toolkit in Sharepoint, and had not had any luck until I spent the whole day debugging and getting it to work. I already had Ajax integrated in Sharepoint, so it should be fairly easy to just add in AjaxControlToolkit, but the problem is the latest version of it actually requires you to use ToolkitScriptManager instead of ScriptManager, otherwise your control will not work and you will see a Javascript error of "Please wait while scripts are loaded".
I had to create a task dynamically in C# and assign the task to a reviewer, which is a user account. However, there was this problem of the "Assigned to" field is only read only. To do that, just create an SPFieldUserValueCollection and assign it to task item.
I needed to get SPUser object from doing a lookup using CAML query, so that I could get the user information such as email address, etc. To do that, this is the code that I used:
I had the problem of not able to debug Sharepoint in Visual Studio 2008 awhile ago, and glad that Aaron shown me how to do it by doing some tricks. What happened was the PDB file might not have been deployed to the assembly GAC.
Today I was testing the loading time of my site, which I sometimes find it slow to access especially the first time loading. I knew there are a lot of images to be loaded especially those in portfolio sections but I also found that the biggest loading item seems to be ScriptResource.axd from Ajax. It was 330kb!
Lookup field is a field which links a child class to a parent class, it is an association kind, which allows a list item to reference another item from another list. However, reading and writing to a lookup field is different from a normal field. We need to use the class SPFieldLookupValue to archieve this.
Creating Update Panel in code behind dynamically can be a bit tricky, comparing to doing it at the front end. Here's a quick view of the code we write to do this.
I was trying to create a web part with WSPBuilder installed on Visual Studio 2008, but had the problem of rendering a user control. Then I came across this blog post, which explains the steps in wrapping usercontrol with WSPBuilder solution. What's even greater is we can setup a structure which seperates the application presentation layer with the WSP project.
Recently, I had the chance to play around with ajaxifying Sharepoint server. As you would have probably known, Ajax is a great feature in .NET 3.5 but MOSS 2007 was shipped before Ajax was out. So, to use it, we just need some configurations done.
One of the best things of using LINQ is how easy we could sort or filter objects with a line of code. Consider we have a generic list of object of Employees and we want to filter them with their age. Using LINQ, we don't have to connect to the data source and get the SQL to do the where query. We can just do something like this...
I recently updated the homepage portfolio section with an Ajax filtering dropdown, allowing readers to filter my portfolio with different technologies and themes. However, that caused my old lightbox effect to lose ground somehow. After days of debugging, I found a way to deal with it, that is...
This has to be pretty simple, but I never actually realised it. That is, when we have a textbox, and a button aside, and we want to enter text into the textbox and do a postback by hitting enter on our keyboard instead of hitting the button aside. This can easily be done by wrapping the controls inside a panel, and then set the defaultButton property to the button's id. Gee, I never knew that...
I recently needed to show a datetime as amount of time left or past. This can be done by using TimeSpan, which you can get by subtracting one DateTime from another...
Jorge pointed out the other day that when we do a lot of string concatenation, it is better to use StringBuilder instead of the String class (e.g. str += "something more"; ). This is because StringBuilder gives a better performance when in memory than the standard String class, which requires garbage collection to remove.
A very easy way to connect ASP.NET application to use MySQL database is to use the MySQL Net Connector. With just the following lines of code, you can easily hookup your ASP.NET application to any MySQL db.
When using radio button in a repeater item template, there's a problem of grouping them to a unique name. Solution can be found: http://www.developer.com/net/asp/article.php/3623096
Ever wanted to create a gradient image dynamically? This can easily be done using C# with the following snipplet of code. We can also specify the width, height, gradient direction (horizontal or vertical), and the two colors. By using LinearGradientMode class, a beautiful gradient image can be drawn in a sec.
Having a working sitemap in an ASP.NET application can't be anymore important. You can use it for navigations, breadcrumbs, etc. The default web.sitemap file is an XML file which provides the root node of the site, the SiteMapProvider used, and tracks the provider objects. System.Web.SiteMap inherits from System.Object. The default provider XMLSiteMapProvider works through the Web.sitemap. Besides being useful for site navigation, the sitemap also provides a easy way for search engines to look for pages on the site.
UserControls are great, particularly in making the code more eye friendly, seperating big bunch of codes into different parts and be able to re-use them throughout the application. However, there are times when we need to reference something in the parent page or control from the usercontrol level. That's when I had an issue today, and finally solved it using the brilliant delegate.
A very useful regular expression for validation Australian wide phone number, including mobile phones. This would accepts all forms of Australian phone numbers in different formats (area code in brackets, no area code, spaces between 2-3 and 6-7th digits, +61 international dialing code).
A very handy tool to compress the annoying webresources.axd script. http://madskristensen.net/post/Compress-WebResourceaxd-in-ASPNET.aspx
Enterprise Library is a very useful component developed by Microsoft to help developers solving many common tasks. One that I use a lot is the data access block, which allows you to run data access query in just one line of code! (Saves all the work in writing a command and pass to a reader, etc).
When using ORM, should always keep in mind that only one object scope is used. The example came with the package doesn't really explain this well. Should always declare a page_init call which declares the object scope and store it in session and try to keep using it for any business operations:
How to convert data to xml file? Here is a very useful command to convert dataset or datatable to an XML Document:
For a method or properties to be overridable, it must has a virtual property in its base class set as true as well, is final must be set as true. To determine whether a method is overridable, it is not sufficient to check that IsVirtual is true.
I stumbled upon an error when deploying a web application onto IIS7 running on Vista. After days of trying to solve, it's actually due to the fact that the application is set to medium trust but it actually needs Full Trust due to using Reflection in the code.
When using ORM, after we have setup the business objects, it's useful if we create some generic methods which can be used in many places.
Telerik ORM (Open Access Mapping) has been a very useful tool, for mapping database structures into object oriented classes, so called Persistent Classes. This saves a lot of efforts in writing up these classes manually. What's more we could add on to it is to use generic methods on standard adding and deleting transaction.
Applying security for a web application is a very common task. There are always parts on a web site that requires private only access for members. Recently, I tried to use the form authentication method provided by .NET and found it quite simple to use, though I have always done it with sessions. The