Wednesday, February 18, 2009
How to use JavaScript to close an IE7 browser window without seeing the confirmation dialog?
<a href="javascript: window.open('','_parent','');window.close();">Close this window!</a><br />
Thursday, December 4, 2008
What is a quick way to get a .NET assembly's PublicKeyToken?
The quick and dirty way is to go into the .NET command prompt and type the following:
sn -T MyDotNetAssembly.dll
The above utilizes the strong name utility that comes with the .NET Framework.
sn -T MyDotNetAssembly.dll
The above utilizes the strong name utility that comes with the .NET Framework.
Wednesday, November 26, 2008
Download tracking with WSS 3.0
WSS 3.0 does not have a mechanism for tracking who downloads which files with authenticated users. When I got confronted with this task, I decided to create a web user control that reads all the files in a document library and subsequently displays the file names using a series of "LinkButton" controls. I then attached this web user control to a SharePoint WSS 3.0 web page. I decided against using a Hyperlink object in favor of a LinkButton ASP.NET control for the following two reasons:
1) With a HyperLink ASP.NET control, users can right-click on the anchor and choose "Save target as" to save the file. This is not desirable because no event is triggered when that happens. On the other hand, a LinkButton control does not produce a right-click popup in a browser leaving the user with no choice but to click on the link.
2) I needed to put some business logic behind the click event of the LinkButton. The business logic essentially saves statistics along the lines of: timestamp, host address, user ID, and filename.
1) With a HyperLink ASP.NET control, users can right-click on the anchor and choose "Save target as" to save the file. This is not desirable because no event is triggered when that happens. On the other hand, a LinkButton control does not produce a right-click popup in a browser leaving the user with no choice but to click on the link.
2) I needed to put some business logic behind the click event of the LinkButton. The business logic essentially saves statistics along the lines of: timestamp, host address, user ID, and filename.
Wednesday, October 22, 2008
How to programatically delete a SharePoint 2007 field belonging to a list or document library?
Here's the code for deleting a field named "phone" in list "myList" on a site with URL http://mysite/:
try {
using (SPSite sitecollection = new SPSite("http://mysite/")) {
using (SPWeb web = sitecollection.OpenWeb()) {
web.AllowUnsafeUpdates = true;
// Delete Sharepoint SPField
web.Lists["myList"].Fields.Delete("phone");
web.Update();
Console.WriteLine("Done deleting column");
}
}
} catch (Exception ex) {
Console.WriteLine(ex.ToString());
}
try {
using (SPSite sitecollection = new SPSite("http://mysite/")) {
using (SPWeb web = sitecollection.OpenWeb()) {
web.AllowUnsafeUpdates = true;
// Delete Sharepoint SPField
web.Lists["myList"].Fields.Delete("phone");
web.Update();
Console.WriteLine("Done deleting column");
}
}
} catch (Exception ex) {
Console.WriteLine(ex.ToString());
}
Tuesday, October 21, 2008
How do you break up a long SharePoint 2007 survey?
What do you do if you have a long SharePoint 2007 survey and you want to break it up into separate pages such that the user needs to click the "Next" button?
Solution:
You must use branching on selected questions for this. All branching items would simply point to the next question. That produces a “Next” button.
Solution:
You must use branching on selected questions for this. All branching items would simply point to the next question. That produces a “Next” button.
Thursday, July 24, 2008
How to use built-in SharePoint 2007 engine to send email?
A straightforward way of sending email from within a SharePoint 2007 application is to use the Object Model. Here is some C# code that will do it for you:
bool isAppendHtmlTag = true;
bool isHtmlEncode = false;
string recipient = "whoever@whatever.com";
string title = "This is the title";
string body = "This is the email <strong>body</strong>";
Microsoft.SharePoint.Utilities.SPUtility.SendEmail(
Microsoft.SharePoint.SPContext.Current.Web,
isAppendHtmlTag,
isHtmlEncode,
recipient,title,
body);
bool isAppendHtmlTag = true;
bool isHtmlEncode = false;
string recipient = "whoever@whatever.com";
string title = "This is the title";
string body = "This is the email <strong>body</strong>";
Microsoft.SharePoint.Utilities.SPUtility.SendEmail(
Microsoft.SharePoint.SPContext.Current.Web,
isAppendHtmlTag,
isHtmlEncode,
recipient,title,
body);
Sunday, July 20, 2008
Generating user instances in SQL Server is disabled. Use sp_configure 'user instances enabled' to generate user instances.
Recently I noticed that many of my ASP.NET applications that work with a SQL Server Express database that resides in the App_Data directory stopped working. The culprit error was "Generating user instances in SQL Server is disabled. Use sp_configure 'user instances enabled' to generate user instances.". I suspect that a SQL Server update went out that disables user instances. I have not been able to substantiate this suspicion yet.
SOLUTION:
The solution is to enable user instances with the following command:
sp_configure 'user instances enabled','1';
Disable user instances with the following command:
sp_configure 'user instances enabled','0';
SOLUTION:
The solution is to enable user instances with the following command:
sp_configure 'user instances enabled','1';
Disable user instances with the following command:
sp_configure 'user instances enabled','0';
Subscribe to:
Posts (Atom)