Wednesday, February 4, 2009

Set FileUpload control in ASP.Net 2.0 to Read-Only?


We can make the ASP.Net FileUpload control readonly by setting the ContentEditable property to false.
<asp:FileUpload ID="fileUploadSri" ContentEditable="false" runat="server" />
The other way of achieving it by restricting users to type in any characters i.e. return false on key press, key up and on paste event to prevent users pasting any values directly.
Refer the below code snippet that helps in doing that,
fileUploadSri.Attributes.Add("onkeypress", "return false;");
fileUploadSri.Attributes.Add("onkeyup", "return false;");
fileUploadSri.Attributes.Add("onpaste", "return false;");

Uploading Files using FileUpload control in Update Panel in ASP.Net AJAX

By default, FileUpload control will not work inside an UpdatePanel control for uploading files using Asynchronous postback. This is because, the file uploading and file manipulations is restricted by default in client side for security reasons. Hence it is not possible to upload files using asynchronous postback in UpdatePanel.

To upload files inside UpdatePanel control we need to rely upon a standard postback i.e. we need to set the button that is uploading the file to be PostBack trigger instead of AsyncPostBack trigger. This will initiate a normal postback whenever we click the upload button and it is possible to upload the file.
Refer the below code for clear understanding,

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:FileUpload ID="fuUpload" runat="server" />
<asp:Button ID="btnUpload" runat="server" OnClick="btnUpload_Click" Text="Upload" />
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="btnUpload" />
</Triggers>
</asp:UpdatePanel>

protected void btnUpload_Click(object sender, EventArgs e)
{
string filename = System.IO.Path.GetFileName(fuUpload.FileName);
fuUpload.SaveAs("C:\temp" + filename);
}


Tuesday, February 3, 2009

Windows 7 - Next OS

Windows 7 , the next client release of Microsoft will be available in 32 & 64-bit versions.
Here are some things that you asked for in your Desktop OS:
For end –users
1. Faster-Your system starts up, shuts down and resumes from standby faster, and your laptop’s battery lasts longer!
2. Touch- Multi touch, ink and gesture support along with handwriting recognition allow you to create exciting new input capabilities. Managing large number of windows is much easier, with intuitive touch gestures to view multiple windows at once and remove unwanted windows.
3. Faster Browsing- Build for the web with IE8, add rich media with Silver light and extend to rich client with WPF – using the same platform and tools
4. Explore and Share - With Windows 7 and Windows Live, you can easily manage your documents, pictures, movies and music, regardless of which PC they are stored on, and share them with your friends and family.
5. Search- Windows 7 includes all performance improvements from Windows Search 4.0, so search and indexing are much faster.
6. Less Crashes- A new feature in Windows 7, Fault Tolerant Heap, mitigates the most common causes of heap corruption, significantly reducing the number of crashes you will experience!
7. Power Saving - Windows 7 easily adapts to your activity. To save battery power, Windows 7 automatically reduces display brightness after a period of inactivity, much like mobile phones do today.
8. Watch complete DVD on battery- Windows 7 will use less power in playing a standard-definition DVD than all earlier versions of Windows, so you are more likely to watch a complete movie with a single battery charge.
Features for IT Pros
1.App Compatibility- Windows 7 will run most if not all applications that run on Windows Vista, making Windows Vista to Windows 7 deployment easier.
2. Powershell v2 - Customers will be able to keep their PCs running smoothly with PowerShell & Group Policy management.
3. Bitlocker To Go- In Windows 7, BitLocker To Go will protect data stored on portable media (e.g., USB Flash Drives, USB Portable Hard Drives) such that only authorized users can read the data, even if the media is lost, stolen, or misused.
4. Work from Anywhere - With the capabilities Windows 7 enables, users who have internet access will be automatically connected to their corporate network. A user who is sitting on a coffee shop can open his laptop, connect to the internet using the wireless access of the coffee shop and start working as if he is in the office. The user in this case will be able to not only use outlook, but also work with intranet sites, open corporate shares, use LOB applications, and basically have full access to corporate resources.
5. “Branch office caching”- The idea is to cache the corporate data downloaded by users locally in the branch office so it can be quickly accessed by others in the branch. With branch office caching, opening a document can take seconds instead of minutes.
6. “Enterprise Search Scopes” enables IT, using Group Policy, to deploy links to appear on the user’s Start menu or in Explorer.
7. AppLocker provides a flexible mechanism that allows administrators to specify exactly what is allowed to run on their systems and gives users the ability to run applications, installation programs, and scripts that administrators have explicitly granted permission to execute. For example, a rule could be written that says “allow all versions greater than 8.1 of the program Photoshop to run if it is signed by the software publisher Adobe.”

Monday, February 2, 2009

Probable Timeout problems in ASP.NET

I've been through almost all sorts of Timeout related issues with Asp.net web service development. I’d like put a check list here to remind myself and hopefully save some headache of yours.
  1. If use database, you may get ‘System.Data.SqlClient.SqlException: Timeout expired’:
    a: Check your connection string setting for ‘Connect Timeout’: I.e.
    connectionString="Data Source=SNYC14D11511;Initial Catalog=d_dbivt003;Persist Security Info=True;User ID= user;Password= Password;
    Connect Timeout=4200

    b:Check your command object
    SqlCommand.CommandTimeout Property, it’s by default 30s
  2. Check you Web.config setting when you get error like ‘Client found response content type of 'text/html; charset=utf-8', but expected 'text/xml'.’:
    ….

    executionTimeout="1200"/>

    make sure your set 'compilation debug="false" as well to let timeout setting take effect. Check MSDN for details.
  3. Set your proxy class Timeout property (derived from WebClientProtocol.Timeout Property) at client if you get error like this ‘The operation has timed out’: I.e.
    proxy.
    Timeout = System.Threading.Timeout.Infinite;
  4. If you are like me, use VistualStudio unit test tool and you get a blue icon and error ‘Timeout’ in your test result pane, you need to check your test config file localtestrun.testrunconfig. The last item ‘Test Timeouts’ is the key. It’s 5 min by default.
  5. Last one and every web developer should know is the IIS server setting such as Keep Alive and Connection Timeout