.NET SummerCamp 2005 Leipzig

Torsten Weber invited me to do one day of sessions at the .NET Summercamp: I introduced .NET 2.0 and C# 2.0 and talked about Visual Studio 2005 Team System. It was the first time in Leipzig and i really liked it. Hopefully i'll be there next year too.

Don't mess with sharepoint...

Carefully said I do not like that sharepoint "hijacks" the Internet Information Server. When you create a virtual directory it is just not accessable because SharePoint took over IIS. Funny fact: This is the second post how to fix issues with IIS and "extension" that cause issues :-) So i decided to hack a small utility serving my needs: ExcludeFromSharepoint.zip (3.46 KB) Enables to exclude applications from sharepoint services through the directory context menu. Install using the "-install" switch; Uninstall using "-uninstall" switch. Because I'm running my machine under a LUA (Limited User Account) i wrote the tool in a way that you can install and uninstall it without administative rights - the contextmenu will be installed per user! if(args[0]=="-install") {     RegistryKey _rkey = Registry.CurrentUser;     _rkey = _rkey.OpenSubKey("SOFTWARE\\Classes",true);     _rkey = _rkey.CreateSubKey("Folder").CreateSubKey("shell");     _rkey = _rkey.CreateSubKey("Exclude from Sharepoint");     _rkey = _rkey.CreateSubKey("command");     _rkey.SetValue(null, App.Application.ExecutablePath + " \"%1\""); } else if(args[0]=="-uninstall") {     RegistryKey _rkey = Registry.CurrentUser;     _rkey = _rkey.OpenSubKey("SOFTWARE\\Classes\\Folder\\shell",true);     _rkey.DeleteSubKeyTree("Exclude from Sharepoint"); } else { ... }   The Implementation works with the webserver extensions version 4.0 or higher       RegistryKey _rkey = Registry.LocalMachine;     _rkey = _rkey.OpenSubKey("SOFTWARE\\Microsoft\\Shared Tools\\" +         "Web Server Extensions",true);         foreach(string _subKeyName in _rkey.GetSubKeyNames())     {         try         {             int.Parse(_subKeyName.Replace(".",""));             RegistryKey _fpKey = _rkey.OpenSubKey(_subKeyName,true);             _fpDir = (string)_fpKey.GetValue("Location");         }         catch(Exception _ex)         {             string _err = _ex.ToString();             break;         }     }   and uses the stsadm.exe from the shared tools of the server extensions.     System.Diagnostics.Process _p = new System.Diagnostics.Process();     _p.StartInfo.FileName = Path.Combine(_fpDir, "BIN\\stsadm.exe");     _p.StartInfo.Arguments = "-o addpath -url http://localhost/" +         _strProjectName + " -type exclusion";     ...     _p.Start();  

ASP.NET Version Issues

I develop with 1.1 and 2.0 - When VS 2003 creates a web solution it is configured to use the 2.0 runtime. Placeing the following code to the Global.asax's of your 1.1 projects and setting execute permissions on the aspnet_regiis.exe helps much. protected void Application_Start(Object sender, EventArgs e) {       if(System.Environment.Version.Major==2)       {             System.Diagnostics.Process _p = new System.Diagnostics.Process();             _p.StartInfo.FileName = "%WINDIR%\\Microsoft.NET\\Framework\\v1.1.4322\\aspnet_regiis.exe";             _p.StartInfo.Arguments = "-s W3SVC/1/ROOT" + Request.ApplicationPath;             _p.StartInfo.UseShellExecute = false;             _p.StartInfo.RedirectStandardOutput = true;             _p.Start();       } }  

Simply resize an uploaded image

I got an E-Mail from a student this morning asking how to thumbnail an uploaded image. Here is a "quick" solution (there are a few things you can do to increase quality, set JPEG compression factor or keep gif transparency). If you like to dig deeper have a look at one of the articles i wrote for the DotNetPro magazine's #Talk column (dnp0305_Thumbnail.pdf [German])   <%@ Page Language="C#" %>   <script runat="server" Language="C#">       public void UploadFile(object sender, EventArgs e)     {         System.Drawing.Image _img =              System.Drawing.Image.FromStream(             this.InputTypeFile.PostedFile.InputStream);           int _maxWidth = 100;         int _maxHeight = 100;           int _width = _img.Width;         int _height = _img.Height;           string _filename =               System.IO.Path.GetFileName(               this.InputTypeFile.PostedFile.FileName);                     string _uploadPath = System.IO.Path.Combine(             Server.MapPath(".\\upload\\"),             _filename);                 if (_width > _height)         {             width = Math.Abs((int)(height *                         _img.Width /                         _img.Height));             _height = _maxHeight;         }         else         {             _height = Math.Abs((int)(_maxWidth *                         _img.Height /                         _img.Width));             _width = _maxWidth;         }                 System.Drawing.Image _newImg =             _img.GetThumbnailImage(width, height, null, null);            _newImg.Save(_uploadPath);            _img.Dispose();     }   </script> <body>     <form id="form1" runat="server">       <input id="InputTypeFile" type="file" runat="server" />     <asp:Button ID="Submit" OnClick="UploadFile" Text="Upload" />       </form> </body> </html>

RE: httpOnly cookies in ASP.NET 1.1

Scott posted a solution to support httpOnly cookies in ASP.NET 1.1 but pointed out some problems when you run the code on 2.0(http://www.hanselman.com/blog/HttpOnlyCookiesOnASPNET11.aspx) Here is a solution: protected void Application_EndRequest(Object sender, EventArgs e) { if(System.Environment.Version.Major<2) { foreach(string cookie in Response.Cookies) { const string HTTPONLY = ";HttpOnly"; string path = Response.Cookies[cookie].Path; if (path.EndsWith(HTTPONLY) == false) { //force HttpOnly to be added to the cookie Response.Cookies[cookie].Path += HTTPONLY; } } } }

Indicate if the current web is running in debug mode...

public static bool IsWebInDebugMode{    get    {        bool _isDebug = false;                if(HttpContext.Current.Cache["IsDebug"]==null)        {            XmlDocument _doc = new XmlDocument();            string _cfgfile = HttpContext.Current.Server.MapPath("~/Web.Config");                _doc.Load(_cfgfile);                        XmlNode _node = _doc.SelectSingleNode("configuration/system.web/compilation");            if(_node==null || _node.Attributes["debug"]==null ||                _node.Attributes["debug"].Value.ToLower()!="true")            {                _isDebug = false;            }            else            {                _isDebug = true;            }            HttpContext.Current.Cache.Insert("IsDebug", _isDebug,                new System.Web.Caching.CacheDependency(_cfgfile),                DateTime.Now.AddDays(1),                TimeSpan.Zero);        }        else        {            _isDebug = bool.Parse(HttpContext.Current.Cache["IsDebug"].ToString());        }                return _isDebug;    }}

.NET 2.0 Only 99.9% backwards compatible?

While re-writing a few WebServices for .NET 2.0 i ran across following: ...public static void WaitProc(object state, bool timedOut){   MyAsyncResult myAsyncResult = (MyAsyncResult)state;   myAsyncResult.OriginalCallback.Invoke(myAsyncResult);}... This compiles without any problems in Visual Studio .NET 2003 but makes the compiler scream (Invoke cannot be called directly on a delegate) untill you change the lines to the following: ...public static void WaitProc(object state, bool timedOut){   MyAsyncResult myAsyncResult = (MyAsyncResult)state;   myAsyncResult.OriginalCallback(myAsyncResult);}...

Using IFused with the FCKEditor

Miroslaw Maslyk has sent this small tutorial on how to use iFused with the FCKEditor. Thank you very much Miro ;-) 1. Rename file FCKeditor\editor\dialog\fck_image.html to fck_image.aspx. 2. On the top this file (fck_image.aspx) add this code: <%@ Page Language="C#" %><%@ Register TagPrefix="Uploader"  namespace="StaticDust.Web.UI.Controls"  assembly="StaticDust.Web.UI.Controls.UploadDialog" %><script runat="server">protected void Page_Load(Object source, EventArgs e) {    StaticDust.Web.UI.Controls.UploadDialogButton _u =      new StaticDust.Web.UI.Controls.UploadDialogButton();    _u.UploadDirectory = "~/images";    _u.ReturnFunction = "SetUrl()";    btnBrowse.Attributes["OnClick"] =      "javascript:" + _u.JavascriptLink; } </script> 3. Find btnBrowse input html tag , add runat="server" attribute and close tag (/>) 4. Replace in files FCKEditor\FCKeditor\editor\js\fckeditorcode_ie_2.js and fckeditorcode_gecko_2.js all fck_image.html sentence to fck_image.aspx