Asp Net Source.com's BlogAspNetSource's Official Blog

asp.net source code blog

Categories

Archives

2/18/2010 - Why is there an ASP.NET account on my machine
1/16/2010 - How to Open a Redirect in a New Window
1/2/2010 - Convert string to datetime Using C#
12/8/2009 - Using ASP.NET FileUpload to work with Images
11/24/2009 - Detect and Replace URLs in Text using Regex
11/17/2009 - Display RSS Feeds Using XmlDataSource
11/12/2009 - Get Current Theme Programmatically
11/10/2009 - Add Default ListItem to a DropDownList Control
10/20/2009 - GridView with LINQ Programatically
9/28/2009 - Server.HtmlEncode vs HttpUtility.HtmlEncode
8/20/2009 - Get List of sub Directories
7/29/2009 - gridview hide header
7/27/2009 - EmptyDataText Property in the Repeater Control
7/11/2009 - XmlDataSource GridView Example
7/5/2009 - Displaying multiple static paths by single page
6/8/2009 - Categories of classes in the System.Security.Cryptography Namespace
6/1/2009 - Delayed Loading of Page Parts
5/7/2009 - Using MySql in ASP.NET project, cofiguring, exaples with SqlDataSource, GridView, etc
4/29/2009 - What Are You Coding Right Now
4/23/2009 - Concat Byte Arrays in C Sharp
4/13/2009 - Visual Studio 2010 is Coming
3/16/2009 - automatic refresh page in some interval with javascript
2/21/2009 - we have just launched a new asp.net related site
2/18/2009 - Try Catch vs. Using
2/10/2009 - How to Set Language in web.config
1/30/2009 - A New Site for Free Online Test for Developers
1/21/2009 - Easy way to send email from gmail account using ASP.NET 3.5
1/15/2009 - Easy way to Dispaly a Word Document in Web Page
12/20/2008 - Create Yes No Voting Control
12/20/2008 - Our Team
12/15/2008 - Select xml node by other node
12/3/2008 - Forget about tedious mistakes when Validate through W3C
11/19/2008 - Fields removed when Download our Products
11/13/2008 - How to select all text in textbox when it gets focus
11/7/2008 - LINQ DataContext Class
11/3/2008 - PNGs and Browser Support
10/28/2008 - Check site loading by different locations in the world
10/27/2008 - Fix the SQL Connection Problems
10/26/2008 - Encrypt Connection Information
10/25/2008 - Generate Sitemap for your Site
10/23/2008 - Introduction to Design Patterns
10/21/2008 - Differences between Components, Controls, and Behaviors
10/20/2008 - What Is LINQ to SQL
10/19/2008 - Evolution of SQL Server
10/16/2008 - Loading Master Pages Dynamically in ASP.NET 3.5
10/15/2008 - A Brief Overview of Validation in ASP.NET 3.5
10/14/2008 - Automatically Hiding the Login Control from Authenticated Users
10/9/2008 - Check the load time of your website
10/5/2008 - Screw it, Lets RE-Design it all
10/2/2008 - Additional ASP.NET AJAX Libraries
9/29/2008 - The Big Problem of WYSIWYG Editors
9/29/2008 - New Forum for ASP.NET and Web Started
9/25/2008 - Optimize Page Loading Part 2 - Tips When work with Images
9/23/2008 - 10 Design Tips
9/19/2008 - C Sharp Features in Framework 3.0
9/15/2008 - Optimize Page Loading - 20 General Tips and Tricks
9/7/2008 - what is asp.net
9/5/2008 - Why Client Validation is not enough to secure our web app
8/29/2008 - Optimize Page Loading when works with DataBase
8/20/2008 - Highlight text in GridView using javascript
8/4/2008 - ContentPlaceHolder in title tag, Is That Bug in VS 2008
8/1/2008 - Why should we use ResolveUrl
7/31/2008 - Guid.TryParse in Framework 3.5
7/30/2008 - Redirect to current page
7/28/2008 - Validate Max Length of TextBox text
7/24/2008 - Easiest way for Row Numbering in GridView
7/23/2008 - Framework 3.5 Disadvantage of lamda expressions
7/21/2008 - LINQ - display filed from parent table in LinqDataSource and GridView
7/17/2008 - LinqDataSource and Guid passed as QueryStringParameter
7/14/2008 - Inappropriate name of DetailsView in msdn
7/9/2008 - Hide form after user download file
7/7/2008 - Menu in Master Page. How to set selected item from Page
7/4/2008 - Overview of New in Framework 3.5
7/2/2008 - New in Framework 3.5 - Generic Class HashSet
7/2/2008 - Present XmlDataSource data with Repeater
7/1/2008 - How to Validate ImageButton control through W3C
6/30/2008 - Using Find Method in Generic Controls With VB.NET - List
6/30/2008 - Using Find Method in Generic Controls With CSharp - List of T
6/30/2008 - Script injections using ASP.NET

References

 
 
posted by Tihomir Ivanov on 18 February 2010 06:29
Posted in: dot-net-framework 
When you install updates or a new software on your pc, you install soem version of Microsoft .NET Framework. It contains a common runtime application that may be required by applications you’re running. During the installation, an account, which is named ASP.NET is created. If your pc previously displayed your desktop immediately after starting, you may notice a ‘Welcome’ screen when you run the computer with your existing user account and an ASP.NET account. It happens because after the installation, there are 2 accounts on your computer.

The account does not allow remote or interactive login and only has "guest" level permissions. It cannot be used by another individual or by Microsoft to log in to your machine.

If you’re just using your computer for personal use (i.e. if you’re not a developer who needs develop software with IIS) you can safely remove this account in one of the following ways:

1) Uninstall the .NET Framework (note: this will cause applications using .NET Framework to stop working):
• Open the Control Panel
• Open Add/Remove Programs
• Select Microsoft .NET Framework 1.1
• Click Change/Remove

2) Delete the account, leaving the Microsoft .NET Framework installed:
• Launch the Computer Management tool within your Administrative Tools folder (under Control Panel)
• Select the Local Users and Groups node
• Click the Users sub node, highlighting the ASPNET account
• Right click the highlighted account and choose delete


Either of way 1 and way 2 will completely remove the ASP.NET account from your system.

Learn More http://support.microsoft.com/default.aspx?scid=kb;en-us;827072
posted by Tihomir Ivanov on 16 January 2010 19:17
Posted in: asp.net 

You may often use the Response's Redirect method to open new pages, ex:

Response.Redirect("http://www.devtheweb.net");

It will open the url in the same window.

If you want to open url by server side in a new window, it cannot be done using the Response's Redirect method.
But it can be done using JavaScript, here is an example:

ClientScript.RegisterStartupScript(typeof(Page), "key", "<script>window.open('http://www.devtheweb.net','_blank')</script>");

posted by Tihomir Ivanov on 02 January 2010 13:37
Posted in: csharp 

Sometimes you may have strings to represent dates (ex. 20100102 that represents 2010 January 2), here's an example how it can be converted to DateTime:

string dtString = "20100102";

IFormatProvider culture = new CultureInfo("en-EN", false);

DateTime dt = DateTime.ParseExact(dtString, "yyyyMMdd", culture, DateTimeStyles.NoCurrentDateDefault);

Now, if you want to convert DateTime variable to string in the format above, here's an example how it can be done:

String dtNewString = String.Format("{0:dd/MM/yyyy}", dt);

 

posted by Tihomir Ivanov on 08 December 2009 16:57
Posted in: asp.net 

I'm writing ability user of my site http://www.devtheweb.net to have ability to change their avatar photos by uploading their own image files.

In this article you can find:
- how to check on server-side if file is selected by FileUpload
- how to check on server-side if Image file is selected by FileUpload
- how to check Image dimensions from file selected by FileUpload

In .aspx file we have a FileUpload Control, Button to submit file and a Label to output result in it:

<div>
  <asp:FileUpload ID="_customImageFU" runat="server" />
</div>
<div>
  <asp:Label ID="_resultLbl" runat="server" ForeColor="Red"></asp:Label>
</div>
<div>
  <asp:Button ID="_uploadImageBtn" runat="server" onclick="_uploadImageBtn_Click" Text="Upload" />
</div>

in code-behind file, we handle the Submit Button Click and check for valid image:

protected void _uploadImageBtn_Click(object sender, EventArgs e)
{
      string extension, filename;

      try
     {
           //t checks if file exists
           if (!_customImageFU.HasFile)
          {
               _resultLbl.Text = "Please, Select a File!";
               return;
          }

          //t checks file extension
         extension = System.IO.Path.GetExtension(_customImageFU.FileName).ToLower();

          if (!extension.Equals(".jpg") && !extension.Equals(".jpeg")
              && !extension.Equals(".gif") && !extension.Equals(".png"))
         {
              _resultLbl.Text = "Only image files (.JPGs, .GIFs and .PNGs) are allowed.";
              return;
          }

          //t checks if image dimensions are valid
         if (!ValidateFileDimensions(100, 100))
        {
             _resultLbl.Text = "Maximum allowed dimensions are: width <= 100px and height <= 100px.";
            return;
        }

        filename = Server.MapPath("~/some_folder/") + "some-file-name" + extension;

       _customAvatarFU.SaveAs(filename);
   }
   catch (Exception)
  {
       //t handle the exception
  }
}

public bool ValidateFileDimensions(int aHeight, int aWidth)
{
       using (System.Drawing.Image image = System.Drawing.Image.FromStream(_customImageFU.PostedFile.InputStream))
      {
           return (image.Height <= aHeight && image.Width <= aWidth);
      }
}

That's all :)

posted by Tihomir Ivanov on 24 November 2009 16:13
Posted in: csharp 

Here's a simple example how you can detect URLs in some text and replace them with html code for hyperlinks:


string someText = "here's a simple text that contains urls in it like http://www.aspnetsource.com or http://aspnetsource.com or http://aspnetsource.com";

// we create a Regex object with pattern to detect URLs
Regex reg = new Regex(@"((http|https|ftp|gopher|telnet|file|notes|ms-help):((//)|(\\\\))*[\w\d:#@%/;$()~_?\+-=\\\.&]*)");

string htmText = reg.Replace(someText, "<a href=\"$1\">$1</a>");

/* now htmlText contains formatted html code with hrefs:

here's a simple text that contains urls in it like <a href="http://www.aspnetsource.com">http://www.aspnetsource.com</a> or <a href="http://aspnetsource.com">http://aspnetsource.com</a> or <a href="http://aspnetsource.com">http://aspnetsource.com</a>

*/

posted by Tihomir Ivanov on 17 November 2009 13:22
Posted in: asp.net 

It's very easy to display RSS Feeds using XmlDataSource and DataList:

Just copy the code below and replace the DataFile value with the RSS Feed url you want

<asp:XmlDataSource ID="RSSDataSource" Runat="server" DataFile="http://www.dev-the-web.com/blog/feed/"
XPath="rss/channel/item" EnableCaching="true" CacheDuration="300" CacheExpirationPolicy="Sliding" />

<asp:DataList ID="dlRSSItems" Runat="server" DataSourceID="RSSDataSource">
<ItemTemplate>
<li><a href='<%# XPath("link") %>'><%# XPath("title") %></a></li>
</ItemTemplate>
</asp:DataList>

That's all :)

posted by Tihomir Ivanov on 12 November 2009 16:40
Posted in: asp.net 

Sometimes it's necessary to get the current Theme Name and it's physical folder path (ex. to check if some file exists in the current theme folder).

We usually define the corrent theme in the WebConfig File:

...
<pages theme="Default" ... >
...

Now, how we could get the current theme name programmatically (C# example):

using System.Web.Configuration;

...

PagesSection pageSection = ConfigurationManager.GetSection("system.web/pages") as PagesSection;

//t pageSection contains property Theme with value - the name of the current Theme
string currentTheme = pageSection.Theme;

//t now we could get the current theme folder physical path
string themeDirPhysicalPath = HttpContext.Current.Server.MapPath("~/App_Themes/" + pageSection.Theme);

...

well, that seems to be All :)

12345678910...


 
Asp Net Source.com


 
Our Sponsors:  Asp.net file upload component  |   Flash file uploader