Wednesday, April 28, 2010
Unable to start debugging on the web server. The server committed a protocol violation. Section=ResponseStatusLine
When try to debug in IIS, visual studio returns following above error:
It was interesting notice that (thanks for following post by Martin) Skype is already occupy the port 80. So IIS is unable to start.
Please un-tick
Skype -> Tools -> Options -> Advanced -> Connection:
Use port 80 and 443 as alternatives for incoming connections - Check box
Reference: The server committed a protocol violation
It was interesting notice that (thanks for following post by Martin) Skype is already occupy the port 80. So IIS is unable to start.
Please un-tick
Skype -> Tools -> Options -> Advanced -> Connection:
Use port 80 and 443 as alternatives for incoming connections - Check box
Reference: The server committed a protocol violation
Could not download the Silverlight application. Check web server settings
Unhandled Error in Silverlight Application Code: 2104
Category: InitializeError
Frequently occures when try to host a silverlight application in a web server which does have following MIME type
File Name Extension: .xap
MIME Type: applicaton/x-silverlight-app
Reference: Register XAP file extention in IIS
Category: InitializeError
Frequently occures when try to host a silverlight application in a web server which does have following MIME type
File Name Extension: .xap
MIME Type: applicaton/x-silverlight-app
Reference: Register XAP file extention in IIS
Thursday, April 22, 2010
Directory Browser using Asp.Net
Demo:
Notes - Functionality:
Next steps
Asp.net Forums
Notes - Functionality:
- RootDirectory default to web application physical directory, using RootDirecotry property you can change it to any destination if you want
- Directory browser lists all the child directories starting from RootDiectory as a treeview
- When you click on any listed directory in the treeview it does a postback and show the directory full path in the text box at the top
- At the initial state text box get the value of root direcotry
- I have implemented direcotory browser as a custom web control. Inheriting WebControl class and INamingContainer interface.
- Default property of this custom web control is DirecotryBrowser
- Default property of the directory browser is RootDirecotry
- SelectedDirectoryName is the output property that you can consume
- In the initializaton phase, control calls CreateControlHeirarchy method to create its controls
- Inside CreateControlHeirarchy it calls a method call AddChildDirectories which accepts two parameters, TreeNode and DirectoryInfo
- AddChildDirectories method lists all the child directories inside a given directory and then its call itslef recursively to list direcotries of child directories of the given directory
- Finally RenderBeginTag, and RenderEndTag wrap the control with <div> tag as my design team always prefer to have div around custom controls over default <span> tag (you would inherit Panel to get rid of this problem but I didnt)
[DefaultProperty("RootDirectory")] public class DirectoryBrowserField : WebField { #region Events public event EventHandler SelectedDirectoryChanged; #endregion #region Attributes TextBox txtDirectoryName = new TextBox(); TreeView treeView = new TreeView(); PlaceHolder contentPlaceHodler = new PlaceHolder(); string baseDirecotry = string.Empty; #endregion #region Properties [DefaultValue("")] [Bindable(true)] public string RootDirectory { get; set; } [DefaultValue("ActiveTextBoxCssClass")] [Bindable(true)] public string TextBoxCssClass { get; set; } [DefaultValue("ActiveTreeViewCssClass")] [Bindable(true)] public string TreeViewCssClass { get; set; } [DefaultValue("")] [Bindable(true)] public string SelectedDirectoryName { get; set; } [DefaultValue(false)] [Bindable(true)] public bool ShowFullPath { get; set; } #endregion #region Constructors public DirectoryBrowserField() { this.Initialize(); } #endregion #region Methods private void Initialize() { this.baseDirecotry = HttpContext.Current.Server.MapPath("~\\"); this.SelectedDirectoryName = this.RootDirectory = HttpContext.Current.Request.PhysicalApplicationPath; this.TextBoxCssClass = "TextBox"; this.TreeViewCssClass = "TreeView"; this.CssClass = this.GetType().Name; this.ShowFullPath = false; } protected override void OnInit(EventArgs e) { base.OnInit(e); if(!this.ChildControlsCreated) this.CreateControlHeirarchy(); } public void CreateControlHeirarchy() { if(!this.RootDirectory.Contains(":\\")) { if (this.RootDirectory.StartsWith("~/")) this.RootDirectory = this.RootDirectory.Replace("~/", "~\\").Replace("/", "\\"); if (this.RootDirectory.StartsWith("/") || this.RootDirectory.StartsWith("\\")) this.RootDirectory = string.Format("~{0}", this.RootDirectory.Replace("/", "\\")); if (this.RootDirectory.StartsWith("~\\")) this.RootDirectory = HttpContext.Current.Server.MapPath(this.RootDirectory); } if (Directory.Exists(this.RootDirectory)) { this.txtDirectoryName.CssClass = this.TextBoxCssClass; this.SelectedDirectoryName = this.RootDirectory; this.txtDirectoryName.Text = this.ResolveDirecotry(); this.contentPlaceHodler.Controls.Add(this.txtDirectoryName); treeView.CssClass = this.TreeViewCssClass; Panel panel = new Panel() { CssClass = string.Format("{0}Wrapper", this.TreeViewCssClass) }; DirectoryInfo root =new DirectoryInfo(this.RootDirectory); TreeNode node = new TreeNode(string.Format(".\\{0}", root.Name), this.RootDirectory); treeView.Nodes.Add(node); this.AddChildDirectories(node, root); foreach (TreeNode n in node.ChildNodes) n.Collapse(); treeView.SelectedNodeChanged += new EventHandler(SelectedNodeChanged); panel.Controls.Add(treeView); this.contentPlaceHodler.Controls.Add(panel); this.Controls.Add(contentPlaceHodler); this.ChildControlsCreated = true; } } private void SelectedNodeChanged(object sender, EventArgs e) { this.SelectedDirectoryName = this.treeView.SelectedNode.Value; this.txtDirectoryName.Text = this.ResolveDirecotry(); if (this.SelectedDirectoryChanged != null) this.SelectedDirectoryChanged(this, e); } private void AddChildDirectories(TreeNode node, DirectoryInfo direcotry) { foreach (DirectoryInfo child in direcotry.GetDirectories()) { TreeNode childNode = new TreeNode(child.Name, child.FullName); node.ChildNodes.Add(childNode); if (child.GetDirectories().Count() > 0) this.AddChildDirectories(childNode, child); } } private string ResolveDirecotry() { if (!this.ShowFullPath) return string.Format(".\\{0}", this.SelectedDirectoryName.Replace(this.baseDirecotry, string.Empty)); return this.RootDirectory; } protected override void RenderContents(HtmlTextWriter writer) { this.RenderFieldLabel(writer); StringBuilder sb = new StringBuilder(); HtmlTextWriter htw = new HtmlTextWriter(new StringWriter(sb)); contentPlaceHodler.RenderControl(htw); base.RenderFieldControl(writer,sb.ToString()); this.RenderFieldValidator(writer); } #endregion }
Next steps
- Add a test page to your web project
- Add Register your control <%@ Register Assembly="Y" Namespace="X" TagPrefix="active" %>
- Utilise your control
- <active:DirectoryBrowser runat="server" ID="dbSample" />
protected void Page_Load(object sender, EventArgs e) { this.dbfBrowse.SelectedDirectoryChanged += new EventHandler(dbfBrowse_SelectedDirectoryChanged); } void dbfBrowse_SelectedDirectoryChanged(object sender, EventArgs e) { DirectoryInfo d = new DirectoryInfo(this.dbfBrowse.SelectedDirectoryName); { foreach (FileInfo f in d.GetFiles()) { string ext = f.Extension.ToLower(); if (ext.Equals("txt") || ext.Equals("doc") || ext.Equals("pdf")) lbxFiles.Items.Add(new ListItem(Path.GetFileName(f.Name), f.Name)); } } }
Asp.net Forums
Friday, April 09, 2010
Can't write to a readonly object Source: NHibernate
This happens when you try to flush the default session with ReadOnlyCache objects. So in your ReadOnlyCached entity repository methods use:
using (new SessionScope(FlushAction.Never)) { entityRepository.FindAll(); }
Subscribe to:
Posts (Atom)
Azure Storage Account Types
Defferent Types of Blobs Block blobs store text and binary data. Block blobs are made up of blocks of data that can be managed individually...
-
Why we need asynchronous tasks? Execute a time consuming operations in parallel to the CLR thread which execute the request If you have ...
-
Demo: I was thinking a way to show images before actually uploading them to server. I would say to preview images using javascript. Obv...