Showing posts with label .NET 3.0. Show all posts
Showing posts with label .NET 3.0. Show all posts

Tuesday, June 20, 2017

Enabling .NET 3.x on Windows 8 and Up

As you may be knowing, now you do not need to separately download and install .Net framework as we used to do with the older .Net frameworks. Since it is coming with Windows, you can just go to “Turn Windows Features On or Off” screen and enable framework you are after. It is simple right?

But in one of the machines it was not that simple for me. The installation tried to download files from Windows Update and was failing mentioning that it cannot get connected to Windows Update when the machine is connected to the internet without any issues.

The solution is to use DISM (Deployment Image Servicing and Management) tool to get it installed.

First you need to find a Windows setup media, a setup DVD or an ISO downloaded will work.

Then use the below command to enable the feature using a local source. Remember to open the Command Window as an Administrator of the machine.

DISM /Online /Enable-Feature /FeatureName:NetFx3 /All /LimitAccess /Source:E:\Sources\sxs

/Online – Targets the currently active and running OS.

/LimitAccess – If some installation files are missing, this will check Windows Update for the missing files. For not to check use /LimitAccess:True.

/Source – Is the location to find the source files, E: is my virtual drive which I mounted the previously downloaded Windows ISO.

If typed correctly, there will be a progress bar showing the installation progress.

image

Monday, December 26, 2016

Open Live Writer – Plugin Not Working

While trying to setup and use the Code Plugin by Rich Hewlett I had trouble getting the plugin loaded into Live Writer. I did add the registry entry required as mentioned in the site, but still the plugin did not load.

Registry

Location - HKEY_CURRENT_USER\SOFTWARE\OpenLiveWriter\PluginAssemblies

Key - SyntaxHighlight_WordPressCom_OLWPlugIn

Value - C:\Users\Arjuna\AppData\Local\OpenLiveWriter\Plugins\SyntaxHighlight_WordPressCom_OLWPlugIn.dll

After a while I figured out that, when loading the plugin Live Writer encounters the following error.

"System.IO.FileLoadException: Could not load file or assembly 'file:///C:\Users\Arjuna\AppData\Local\OpenLiveWriter\Plugins\SyntaxHighlight_WordPressCom_OLWPlugIn.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)
File name: 'file:///C:\Users\Arjuna\AppData\Local\OpenLiveWriter\Plugins\SyntaxHighlight_WordPressCom_OLWPlugIn.dll' ---> System.NotSupportedException: An attempt was made to load an assembly from a network location which would have caused the assembly to be sandboxed in previous versions of the .NET Framework. This release of the .NET Framework does not enable CAS policy by default, so this load may be dangerous. If this load is not intended to sandbox the assembly, please enable the loadFromRemoteSources switch. See http://go.microsoft.com/fwlink/?LinkId=155569 for more information.

This is due to a security feature of .Net Framework 4 or later. Before framework 4, if a DLL is downloaded (which is created in another computer), they used to run in full trust in the zone the assembly is running, but with frameworks 4 and later, downloaded DLLs will not run by default. To make them run, simply grant the DLL full access by going to file properties and selecting the Unblock checkbox in the security section as seen in the below image. This will apply to any plugin you download from internet. Also keep in mind to do this to DLLs you trust safe. Otherwise your computer will be unsafe.

image

To troubleshoot plugin and other errors you can refer to Open Live Writer log file located in C:\Users\Arjuna\AppData\Local\OpenLiveWriter\Open Live Writer.log.

Saturday, August 18, 2012

Handler was not added through the Sys.UI.DomEvent.addHandler method.

imageimage

Sometime back I started getting this error in all the forms in which AJAX tools were used. The thing worried me most is that there were no changes made to the project source code. Later a friend of mine found that it is happening because of the wrong AjaxControlToolkit.

As I feel this dll swap happens when a control is dragged from the Visual Studio toolbox because the toolbox is referenced to a newer version of the toolkit than the project was using.

If you are also getting this error simply delete all the AJAX related files and folders in your projects’ bin directory. Once you are done there should not be any folders such as ar, cs, de, etc. Also remove the AjaxControlToolkit.dll. Then copy the version of the toolkit dll your project was using earlier to the Bin directory. Now clean and build your project to see the error disappear.

If you are still getting the error after correctly doing all this you might be getting the error due to another reason causing the same error. Since there are many reasons for this same error you better check the internet for other reasons to find out the exact reason causing the error for you.

Thursday, August 16, 2012

Correcting AJAX Calendar Extender Popup Calendar Position

Recently I encountered a positioning error in AJAX calendar extender. When I use the calendar extender inside of other container controls the popup calendar started appearing few inches above the button. You will be able to get an idea of the problem by the following image.

image_thumb

Since I couldn’t get it fixed by changing the properties I thought to find a solution for this.

One way to correct this is by applying a CSS style sheet to change the calendar positioning manually. I found this method while searching the web. This way since you need to enter the location of the calendar you need to try several times to get the correct positioning. If you are using this method simply place the following CSS style in your page and apply the style as shown. Remember you need to change the value to suit your form.

  1. <style type="text/css">
  2.     .fromDtPos
  3.     {
  4.         left: 245px !important;
  5.     }
  6. </style>

Apply the style to your calendar extender.

  1. <cc2:calendarextender id="calExpiry" runat="server" targetcontrolid="txtExpiry"
  2.     format="dd MMM yyyy" popupbuttonid="imgExpiry" enabled="True" cssclass="ajax__calendar fromDtPos">
  3. </cc2:calendarextender>

My preferred way to do this is by using the JavaScript that I wrote below. Since you do not need to enter the position manually this will be easier. Also this code will work irrespective of the number of parent containers it is having above of the control.

Insert the below JavaScript into your page.

  1. <script type="text/javascript" language="javascript">
  2.     function showCalendar(sender, args) {
  3.         var processingControl = $get(sender._button.id); // Getting the control which triggered the calendar.
  4.         sender._popupDiv.parentElement.style.top = processingControl.offsetTop + processingControl.height + 'px';
  5.         sender._popupDiv.parentElement.style.left = processingControl.offsetLeft + 'px';
  6.  
  7.         var positionTop = processingControl.height + processingControl.offsetTop;
  8.         var positionLeft = processingControl.offsetLeft;
  9.         var processingParent;
  10.         var continueLoop = false;
  11.  
  12.         do {
  13.             // If the control has parents continue loop.
  14.             if (processingControl.offsetParent != null) {
  15.                 processingParent = processingControl.offsetParent;
  16.                 positionTop += processingParent.offsetTop;
  17.                 positionLeft += processingParent.offsetLeft;
  18.                 processingControl = processingParent;
  19.                 continueLoop = true;
  20.             }
  21.             else {
  22.                 continueLoop = false;
  23.             }
  24.         } while (continueLoop);
  25.  
  26.         sender._popupDiv.parentElement.style.top = positionTop + 'px';
  27.         sender._popupDiv.parentElement.style.left = positionLeft + 'px';
  28.     }
  29. </script>

Then call the function showCalendar on onClientShown event of the calendar extender as seen below.

  1. <cc2:calendarextender id="calExpiry" runat="server" targetcontrolid="txtExpiry"
  2.     format="dd MMM yyyy" popupbuttonid="imgExpiry" enabled="True" onclientshown="showCalendar">
  3. </cc2:calendarextender>

Both of the above methods will correct the appearance of the popup calendar of the AJAX Calendar Extender as seen below.

image_thumb1

Wednesday, July 25, 2012

Styles missing in CalendarExtender

When you put an Ajax Calendar Extender inside of a GridView you will see the calendar without any styling on it meaning the calendar will show only the dates overlapping with other items on your form. Sometimes some dates might even be missing. See the sample appearances below.

imageimageimage

This happens because the style sheets are not loaded at the correct time due to a bug in toolkit, there are several ways to fix this.

One is to add another calendar extender outside of the update panel and keep it hidden.

Another is to disable partial rendering in the script manager. But this will slow down your site reducing the benefits gained from AJAX.

  1. <asp:ScriptManager ID="ScriptManager1" EnablePartialRendering="false" runat="server">
  2. </asp:ScriptManager>

My chosen method is to add the styles manually to the style sheet. To move forward this way simply copy the following styles which are used by the calendar extender to your style sheet.

  1. .ajax__calendar_container {padding:4px;cursor:default;width:170px;font-size:11px;text-align:center;font-family:tahoma,verdana,helvetica;}
  2. .ajax__calendar_body {height:139px;width:170px;position:relative;overflow:hidden;margin:auto;}
  3. .ajax__calendar_days, .ajax__calendar_months, .ajax__calendar_years {top:0px;left:0px;height:139px;width:170px;position:absolute;text-align:center;margin:auto;}
  4. .ajax__calendar_container TABLE {padding:0px;margin:0px;font-size:11px;}
  5. .ajax__calendar_container TD {padding:0px;margin:0px;font-size:11px;}
  6. .ajax__calendar_header {height:20px;width:100%;}
  7. .ajax__calendar_prev {cursor:pointer;width:15px;height:15px;float:left;background-repeat:no-repeat;background-position:50% 50%;background-image:url(../images/arrow-left.gif);}
  8. .ajax__calendar_next {cursor:pointer;width:15px;height:15px;float:right;background-repeat:no-repeat;background-position:50% 50%;background-image:url(../images/arrow-right.gif);}
  9. .ajax__calendar_title {cursor:pointer;font-weight:bold; margin-left:15px; margin-right:15px;}
  10. .ajax__calendar_footer {height:15px;}
  11. .ajax__calendar_today {cursor:pointer;padding-top:3px;}
  12. .ajax__calendar_dayname {height:17px;width:17px;text-align:right;padding:0 2px;}
  13. .ajax__calendar_day {height:17px;width:18px;text-align:right;padding:0 2px;cursor:pointer;}
  14. .ajax__calendar_month {height:44px;width:40px;text-align:center;cursor:pointer;overflow:hidden;}
  15. .ajax__calendar_year {height:44px;width:40px;text-align:center;cursor:pointer;overflow:hidden;}
  16.  
  17. .ajax__calendar .ajax__calendar_container {border:1px solid #646464;background-color:#ffffff;color:#000000;}
  18. .ajax__calendar .ajax__calendar_footer {border-top:1px solid #f5f5f5;}
  19. .ajax__calendar .ajax__calendar_dayname {border-bottom:1px solid #f5f5f5;}
  20. .ajax__calendar .ajax__calendar_day {border:1px solid #ffffff;}
  21. .ajax__calendar .ajax__calendar_month {border:1px solid #ffffff;}
  22. .ajax__calendar .ajax__calendar_year {border:1px solid #ffffff;}
  23.  
  24. .ajax__calendar .ajax__calendar_active .ajax__calendar_day {background-color:#edf9ff;border-color:#0066cc;color:#0066cc;}
  25. .ajax__calendar .ajax__calendar_active .ajax__calendar_month {background-color:#edf9ff;border-color:#0066cc;color:#0066cc;}
  26. .ajax__calendar .ajax__calendar_active .ajax__calendar_year {background-color:#edf9ff;border-color:#0066cc;color:#0066cc;}
  27.  
  28. .ajax__calendar .ajax__calendar_today .ajax__calendar_day {border-color:#0066cc;}
  29. .ajax__calendar .ajax__calendar_today .ajax__calendar_month {border-color:#0066cc;}
  30. .ajax__calendar .ajax__calendar_today .ajax__calendar_year {border-color:#0066cc;}
  31.  
  32. .ajax__calendar .ajax__calendar_other .ajax__calendar_day {background-color:#ffffff;border-color:#ffffff;color:#646464;}
  33. .ajax__calendar .ajax__calendar_other .ajax__calendar_year {background-color:#ffffff;border-color:#ffffff;color:#646464;}
  34.  
  35. .ajax__calendar .ajax__calendar_hover .ajax__calendar_day {background-color:#edf9ff;border-color:#daf2fc;color:#0066cc;}
  36. .ajax__calendar .ajax__calendar_hover .ajax__calendar_month {background-color:#edf9ff;border-color:#daf2fc;color:#0066cc;}
  37. .ajax__calendar .ajax__calendar_hover .ajax__calendar_year {background-color:#edf9ff;border-color:#daf2fc;color:#0066cc;}
  38.  
  39. .ajax__calendar .ajax__calendar_hover .ajax__calendar_title {color:#0066cc;}
  40. .ajax__calendar .ajax__calendar_hover .ajax__calendar_today {color:#0066cc;}
  41.  
  42. /* styles for invalid dates as defined by startDate and endDate*/
  43. .ajax__calendar .ajax__calendar_invalid .ajax__calendar_day {background-color:#ffffff;border-color:#ffffff; color:#646464; text-decoration:line-through; cursor:default;}
  44. .ajax__calendar .ajax__calendar_invalid .ajax__calendar_month {background-color:#ffffff;border-color:#ffffff; color:#646464; text-decoration:line-through; cursor:default;}
  45. .ajax__calendar .ajax__calendar_invalid .ajax__calendar_year {background-color:#ffffff;border-color:#ffffff; color:#646464; text-decoration:line-through; cursor:default;}
  46.   .ajax__calendar .ajax__calendar_invalid .ajax__calendar_today{visibility:hidden; cursor:default;}

Note that the above CSS uses the “arrow-left.gif” and “arrow-right.gif” for the previous and next buttons. If you want, you can use any other image which suits you. In case you need the originals they are below. To correctly show the previous and next buttons you need to place these images on to the “Images” folder under your project. If the folder is different in your project please change the image paths in the above CSS.

  • arrow-left.gif - arrow-left
  • arrow-right.gif - arrow-right

After doing all this remember to link the style sheet to your web page.

  1. <link href="Styles/Site.css" rel="stylesheet" type="text/css" />

If you have done everything correctly your calendar will be shown properly while residing inside of the grid.

image

Monday, December 05, 2011

Developing iPhone and Android Applications using C# .Net

Being a .Net developer did you think how great if you could develop applications for most popular mobile device platforms like iPhone and Android with the .Net skills you already have. If you were thinking like me then the wait is over.

Now with Mono you can create cross platform applications using your .Net framework skills. Mono is a software platform using which you can develop applications which runs on iPhones, Android devices, iPads and iPod Touches.

As per the Mono site, “The Mono Project is an open development initiative sponsored by Novell to develop an open source, UNIX version of the Microsoft .NET development platform.” If you are wondering about the name Mono, it is 'monkey' in Spanish.

You can try Mono for free by downloading the trial by going to the trial link. The good thing is after installing Mono you can use the more familiar Visual Studio to do the development using the available Mono templates.

Friday, November 26, 2010

Disabling Browser Back Button after Logout

Recently in an application we developed there was a requirement to stop the browser back button after user logs out of the application.

The reason behind this was to stop the security risk of another user without proper permissions peeking into the earlier users screens. If you notice in many applications if the browser back is not properly handled then after the user is logged out you can re visit the site by just pressing the browser back button. This happens because the browser shows the cached page when the back is pressed. Even if you have server side code to check for the user they will not fire since the page will load from cache.

With the limited time I found a genius idea to handle this in the internet. What this javascript does is it will always try to put the user back to the last page in the history. For example, I am having a login page and a default page which I am taking a user after he logs in. You need to place the following javascript in the default page to make the above happen.





  1. <script type="text/javascript" language="JavaScript">
  2.     window.history.forward(1);
  3. </script>




Then once a user logs out from the system and if presses the back button of the browser, when the default page loads it will put the user again to login (history forward) page which is the login page. Ultimately user needs to login again to go back to the site.

Tuesday, November 02, 2010

Sorting SharePoint Folder Contents

Recently I needed to sort the contents of a SharePoint folder, in which I used IComparer to get my task done. Following is the code I used. Hope it is helpful.

As you see below I am using the TimeCreated property of SPFile object to do the comparison, other than this you can use any other property of the SPFile object. For a list of available properties refer MSDN.





  1. // Comparer Class.
  2. public class SPFilesComparer : IComparer
  3. {
  4.     #region IComparer Members
  5.     public int Compare(object object1, object object2)
  6.     {
  7.         return new CaseInsensitiveComparer().Compare(((SPFile)object1).TimeCreated, ((SPFile)object2).TimeCreated);
  8.     }
  9.     #endregion
  10. }








  1. ArrayList fileList = new ArrayList(attachFiles);
  2. IComparer compFiles = new SPFilesComparer();
  3. // Do the sorting based on the SPFilesComparer.
  4. fileList.Sort(compFiles);
  5. foreach (SPFile attachFile in fileList)
  6. {
  7.     // Use the sorted list.
  8. }




Saturday, October 02, 2010

MaxLength property not Working in TextBox

If you are involved in coding using .Net sooner or later you will notice that when the TextMode of a TextBox is changed to MultiLine the MaxLength property will stop working. What this means is in the textbox users will be able to type as many character as they want.

When searching the web for a fix for this I found several ideas to solve this. Following is the code which I modified for my requirement. Hope this helps.

ASPX





  1. <html xmlns="http://www.w3.org/1999/xhtml">
  2. <head runat="server">
  3. <script type="text/javascript">
  4.     function RestrictLength(textBox) {
  5.         /* Get the Max Length attribute's value. */
  6.         var allowedLength = textBox.getAttribute('MaximumLength');
  7.         /* Check for the number of characters typed in by the user. */
  8.         if (textBox.value.length > allowedLength) {
  9.             /* If it is more than the allowed limit remove the additional text. */
  10.             textBox.value = textBox.value.substring(0, allowedLength);
  11.             /*  Show a message to user with the tooltip used for the textbox. */
  12.             alert("Maximum characters allowed for '" + textBox.title +"' is " + allowedLength + ".");
  13.         }
  14.     }
  15. </script>
  16.     <title></title>
  17. </head>
  18. <body>
  19.     <form id="form1" runat="server" style="vertical-align:top;">
  20.     <!-- I am binding my java script to the onkeyup event of the textbox. So each time a key
  21.     is pressed it will fire my javascript. -->
  22.     Address <asp:TextBox ID="TextBox1" runat="server" MaxLength="10"
  23.         onkeyup="RestrictLength(this);" Height="58px" TextMode="MultiLine"></asp:TextBox>
  24.     </form>
  25.     </body>
  26. </html>




 

ASPX.CS





  1. protected void Page_Load(object sender, EventArgs e)
  2. {
  3.     // Adding the attribute to the TextBox1.
  4.     // Note that this is different to the MaxLength property.
  5.     // Also this is not case sensitive.
  6.     TextBox1.Attributes.Add("maximumlength", "10");
  7.     // Adding a tooltip which is used in the message.
  8.     TextBox1.ToolTip = "User Address";
  9. }




The output will me something similar to the following.

Tuesday, August 03, 2010

Rounding a value Down

If you did work with .Net Math classes you may have noted that you can quite easily round value upwards. But what about rounding values down?

For example if you tried to round the value 1.23501 into 2 decimal places using the Round method provided by the Math class as below, the result you will get is 1.24. Meaning .Net had rounded the value up.





  1. double dbl = Math.Round(1.23501, 2);




If the value is rounded down it should be 1.23, but in .Net I couldn’t find an easy way to get this done. So I did create a small code to get it done. It is very simple only a method with one statement as shown below.





  1. double RoundDown(double Number, int Digits)
  2. {
  3.     try
  4.     {
  5.         return Math.Truncate(Number) +
  6.             (Math.Floor(Math.Round((Number % 1), Digits) * Math.Pow(10, (Math.Round((Number % 1), Digits).ToString().Length - 3)))) *
  7.             (1 / Math.Pow(10, Math.Round((Number % 1), Digits).ToString().Length - 3));
  8.     }
  9.     catch (Exception)
  10.     {
  11.         MessageBox.Show("Error ! Please check values.");
  12.         return 0.0;
  13.     }
  14. }




Ohh, I think this is complicated right? Please find a bit of self explanatory code below.





  1. double RoundDownExplained(double Number, int Digits)
  2. {
  3.     try
  4.     {
  5.         // Get the whole number from the double value.
  6.         // For example we'll take Number = 788.34567 and Digits = 3.
  7.         // WholeNumberPart = 788.
  8.         double WholeNumberPart = Math.Truncate(Number);
  9.         // Getting the decimal part from the doouble value.
  10.         // DecimalNumberPart = 0.3457.
  11.         double DecimalNumberPart = Math.Round((Number % 1), Digits);
  12.         // Finding the number of decimal places so we can multiply by 10 to make it suitable for Floor().
  13.         // MultiplicationValue = 3.
  14.         int MultiplicationValue = Math.Round((Number % 1), Digits).ToString().Length - 3;
  15.         // Create the double value to round down.
  16.         // RoundedDownValue = 345.
  17.         double RoundedDownValue = Math.Floor(DecimalNumberPart * Math.Pow(10, MultiplicationValue));
  18.         // Finding the value to devide the result to make it decimal again.      
  19.         // DivisionValue = 0.001.            
  20.         double DivisionValue = 1 / Math.Pow(10, MultiplicationValue);
  21.         // Creating the decimal part with rounded down value.
  22.         // RoundedDownValue_Float = 0.345.
  23.         double RoundedDownValue_Float = RoundedDownValue * DivisionValue;
  24.         // Creating the full rounded down value.
  25.         // return = 788.345.
  26.         return WholeNumberPart + RoundedDownValue_Float;
  27.     }
  28.     catch (Exception)
  29.     {
  30.         MessageBox.Show("Error ! Please check values.");
  31.         return 0.0;
  32.     }
  33. }




The complete code of the application I created is below with a screenshot of the application running. Hope this helps to you.





  1. using System;
  2. using System.Text;
  3. using System.Windows.Forms;
  4. namespace WindowsFormsApplication1
  5. {
  6.     public partial class Form1 : Form
  7.     {
  8.         public Form1()
  9.         {
  10.             InitializeComponent();
  11.         }
  12.         double RoundDown(double Number, int Digits)
  13.         {
  14.             try
  15.             {
  16.                 return Math.Truncate(Number) +
  17.                     (Math.Floor(Math.Round((Number % 1), Digits) * Math.Pow(10, (Math.Round((Number % 1), Digits).ToString().Length - 3)))) *
  18.                     (1 / Math.Pow(10, Math.Round((Number % 1), Digits).ToString().Length - 3));
  19.             }
  20.             catch (Exception)
  21.             {
  22.                 MessageBox.Show("Error ! Please check values.");
  23.                 return 0.0;
  24.             }
  25.         }
  26.         double RoundDownExplained(double Number, int Digits)
  27.         {
  28.             try
  29.             {
  30.                 // Get the whole number from the double value.
  31.                 // For example we'll take Number = 788.34567 and Digits = 3.
  32.                 // WholeNumberPart = 788.
  33.                 double WholeNumberPart = Math.Truncate(Number);
  34.                 // Getting the decimal part from the doouble value.
  35.                 // DecimalNumberPart = 0.3457.
  36.                 double DecimalNumberPart = Math.Round((Number % 1), Digits);
  37.                 // Finding the number of decimal places so we can multiply by 10 to make it suitable for Floor().
  38.                 // MultiplicationValue = 3.
  39.                 int MultiplicationValue = Math.Round((Number % 1), Digits).ToString().Length - 3;
  40.                 // Create the double value to round down.
  41.                 // RoundedDownValue = 345.
  42.                 double RoundedDownValue = Math.Floor(DecimalNumberPart * Math.Pow(10, MultiplicationValue));
  43.                 // Finding the value to devide the result to make it decimal again.      
  44.                 // DivisionValue = 0.001.            
  45.                 double DivisionValue = 1 / Math.Pow(10, MultiplicationValue);
  46.                 // Creating the decimal part with rounded down value.
  47.                 // RoundedDownValue_Float = 0.345.
  48.                 double RoundedDownValue_Float = RoundedDownValue * DivisionValue;
  49.                 // Creating the full rounded down value.
  50.                 // return = 788.345.
  51.                 return WholeNumberPart + RoundedDownValue_Float;
  52.             }
  53.             catch (Exception)
  54.             {
  55.                 MessageBox.Show("Error ! Please check values.");
  56.                 return 0.0;
  57.             }
  58.         }
  59.         private void button1_Click(object sender, EventArgs e)
  60.         {
  61.             try
  62.             {
  63.                 label1.Text = RoundDown(double.Parse(textBox1.Text), int.Parse(textBox2.Text) + 1).ToString();
  64.             }
  65.             catch (Exception)
  66.             {
  67.                 MessageBox.Show("Error ! Please check values.");
  68.             }
  69.         }
  70.         private void button2_Click(object sender, EventArgs e)
  71.         {
  72.             try
  73.             {
  74.                 label2.Text = RoundDownExplained(double.Parse(textBox1.Text), int.Parse(textBox2.Text) + 1).ToString();
  75.             }
  76.             catch (Exception)
  77.             {
  78.                 MessageBox.Show("Error ! Please check values.");
  79.             }
  80.         }
  81.     }
  82. }




Saturday, July 31, 2010

Error Accessing Path

Today is a day full of errors, when I fixed one error another error came while trying to run my hosted application. This time it was “Access to the path 'C:\inetpub\wwwroot\……’ is denied.

Full error is as follows,

Access to the path 'C:\inetpub\wwwroot\Mining2 Setup\Images\temp\tempImage.png' is denied.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.UnauthorizedAccessException: Access to the path 'C:\inetpub\wwwroot\Mining2 Setup\Images\temp\tempImage.png' is denied.

image_thumb[2]

The issue here was generated by a code written in my application which tries to access an image named tempImage.png in the said folder (Images\temp).

The reason for this is when you install IIS 7 the account used by the application pool (IIS_IUSRS) is not given access to the folder Images\temp. Since it is created by the application I just installed.

To sort out the issue give write permission to the folder Images\temp for the account IIS_IUSRS using the security tab in the folder properties page.

image_thumb[4]

Friday, July 30, 2010

Error when Installing MSI

Recently when trying to install a setup I made for a project on a new server having Windows Server 2008 R2 I continuously encountered an error as of below.

“The installer was interrupted before “Application” could be installed. You need to restart the installer to try again.”

image_thumb[2]

The server had IIS 7, .Net Framework 3.5 and 4 installed. After putting in some time onto this I found out that this is because the II6 Management Compatibility services was not installed for the Web Server role.

To fix it simply open the Server Manager and open up Web Server role and click on Add Role Services.

image Then select IIS 6 Management Compatibility node and all the child nodes below in under the Management Tools parent node and press next.

image When the installation is complete the setup will work as desired.

image_thumb[4]

Friday, July 23, 2010

Changing the Control Style at Runtime using the ASPX

Recently I changed the style of some controls in my ASPX page at runtime based on the values set on another control in my page. For example the color of the table is changed based on the radio button that was selected and the color of the button is changed according to the text that was typed in the textbox. Hope this is helpful.





  1. <html xmlns="http://www.w3.org/1999/xhtml">
  2. <head runat="server">
  3.     <title>Changing the Control Style</title>
  4.      <style type="text/css">
  5.         .Style1
  6.         {
  7.             background-color: Red;
  8.         }
  9.         .Style2
  10.         {
  11.             background-color: Blue;
  12.         }
  13.     </style>
  14. </head>
  15. <body>
  16.     <form id="form1" runat="server">
  17.         <asp:RadioButton ID="RadioButton1" runat="server" Text="Red" GroupName="1" Checked="True" AutoPostBack="True" />
  18.         <asp:RadioButton ID="RadioButton2" runat="server" Text="Blue" GroupName="1" AutoPostBack="True" />
  19.         <!-- Styling the table based on the radio button selection. -->
  20.         <table class="<% if(RadioButton1.Checked) { %> Style1 <% } else { %> Style2 <% } %>">
  21.             <tr>
  22.                 <td> &nbsp; See the change... </td>
  23.             </tr>
  24.             <tr>
  25.                 <td> &nbsp; </td>
  26.             </tr>
  27.         </table>
  28.         <asp:TextBox ID="TextBox1" runat="server" MaxLength="3"></asp:TextBox>
  29.         <!-- Styling the button based on the textbox value. -->
  30.         <input id="Button1" type="submit" value="button"
  31.                class="<% if(TextBox1.Text=="") { %> Style1 <% } else { %> Style2 <% } %>" />
  32.     </form>
  33. </body>
  34. </html>




Output looks as below.