Tuesday, 31 July 2012

UpdatePanel's UpdateMode to Conditional

ASP.NET Ajax UpdatePanel is that its contents are updated asynchronously when an event that would normally generate a postback is raised inside, one would think that this is its default behavior.
But it's not: the UpdateMode property of the UpdatePanel has 2 possible values:
  • Always
  • Conditional
and the default value is Always.
When set to Always, the UpdatePanel is updated on every postback raised from anywhere in the page, so from controls inside the panel, inside other panels or just on the page.
When set to Conditional, the UpdatePanel will be updated only on postback originated by controls inside the panel or from the triggers specified.
So, if you have multiple update panels and you don't want to update all of them to be updated every time, you have to set the UpdateMode to Conditional:

<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">

Reference:

HTML To Word Document using OpenXMl



Download OpenXMLSDKTool.msi  and run it, you will  get DocumentFormat.OpenXml.dll 

From this link you will get HTMLtoOpenXML.dll

Add these two reference.

using System.IO;
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Wordprocessing;
using NotesFor.HtmlToOpenXml;
...

static void Main(string[] args)
{
     const string filename = "D:\test.docx";
     string html = "<font size='10' face='arial'>Hi this is html to word convert</font>" ;

     if (File.Exists(filename)) File.Delete(filename);

     using (MemoryStream generatedDocument = new MemoryStream())
     {
          using (WordprocessingDocument package = WordprocessingDocument.Create(generatedDocument, WordprocessingDocumentType.Document))
          {
               MainDocumentPart mainPart = package.MainDocumentPart;
               if (mainPart == null)
               {
                    mainPart = package.AddMainDocumentPart();
                    new Document(new Body()).Save(mainPart);
               }

               HtmlConverter converter = new HtmlConverter(mainPart);
               Body body = mainPart.Document.Body;

               var paragraphs = converter.Parse(html);
               for (int i = 0; i < paragraphs.Count; i++)
               {
                    body.Append(paragraphs[i]);
               }

               mainPart.Document.Save();
          }

          File.WriteAllBytes(filename, generatedDocument.ToArray());
     }

     System.Diagnostics.Process.Start(filename);
}
                                                                 





Monday, 30 July 2012

add Subscript and Superscript text in a paragraph in the Word Document using OpenXML SDK


using (WordprocessingDocument wordDocument =
              WordprocessingDocument.Create(filepath, WordprocessingDocumentType.Document))
                {
                    // Add a main document part.
                    MainDocumentPart mainPart = wordDocument.AddMainDocumentPart();

                    // Create the document structure and add some text.
                    mainPart.Document = new Document();
                    Body body = mainPart.Document.AppendChild(new Body());
                    Paragraph para = body.AppendChild(new Paragraph());
                    Run run = para.AppendChild(new Run());

                    RunProperties runProperties = new RunProperties();

                    //font family
                    RunFonts font1 = new RunFonts() { Ascii = "Arial" };
                    run.AppendChild(font1);

                    //font size
                    FontSize fs = new FontSize();
                    fs.Val = "22";
                    runProperties.AppendChild(fs);


                    //Super script
                    VerticalTextAlignment v = new VerticalTextAlignment();
                    v.Val = VerticalPositionValues.Superscript;
                    runProperties.AppendChild(v);
                    run.AppendChild(runProperties);
                    run.AppendChild(new Text("Create text in body – CreateWordprocessingDocument  using Superscript"));

                    mainPart.Document.Save();

                    wordDocument.Close();
                }

Thursday, 26 July 2012

The page you are requesting cannot be served because of the extension configuration. If the page is a script, add a handler. If the file should be downloaded, add a MIME map.


HTTP Error 404.3 - Not Found The page you are requesting cannot be served because of the extension configuration. If the page is a script, add a handler. If the file should be downloaded, add a MIME map.
Here's a screenshot of the error page: alt text










Solution:


Use aspnet_regiis.exe to register version of .NET framework you are using.
This is a comon issue and happens when IIS is installed after VS or .NET framework.
  
Version of .NET Framework
Location of Aspnet_regiis.exe file
.NET Framework version 1
%windir%\.NET\Framework\v1.0.3705
.NET Framework version 1.1
%windir%\Microsoft.NET\Framework\v1.1.4322
.NET Framework version 2.0, version 3.0, and version 3.5 (32-bit systems)
%windir%\Microsoft.NET\Framework\v2.0.50727
.NET Framework version 2.0, version 3.0, and version 3.5 (64-bit systems)
%windir%\Microsoft.NET\Framework64\v2.0.50727

Eg:
1. Run the command prompt (cmd)
2.Navigate to C:\Windows\Microsoft.NET\Framework\v2.0.50727
3.Run this command aspnet_regiis.exe –i




ASP.Net Config Error: "This configuration section cannot be used at this path."


I recently setup an ASP.Net 3.5 web application on a new Windows 2008 R2 server with IIS 7 and ran into a few issues.  I will post about them all under the tag: “asp.net 3.5 with iis 7“.
After setting up the file system and creating the application, I tried to load the default document in a browser and got:
HTTP Error 500.19 – Internal Server Error
The requested page cannot be accessed because the related configuration data for the page is invalid.
Module IIS Web Core
Notification BeginRequest
Handler Not yet determined
Error Code 0×80070021
Config Error This configuration section cannot be used at this path. This happens when the section is locked at a parent level. Locking is either by default (overrideModeDefault=”Deny”), or set explicitly by a location tag with overrideMode=”Deny” or the legacy allowOverride=”false”.
Module IIS Web Core Notification BeginRequest Handler Not yet determined Error Code 0×80070021 Config Error This configuration section cannot be used at this path. This happens when the section is locked at a parent level. Locking is either by default (overrideModeDefault=”Deny”), or set explicitly by a location tag with overrideMode=”Deny” or the legacy allowOverride=”false”.
The solution was to make a change in the applicationHost.config file.
1.    Browse to “C:\Windows\System32\inetsrv\config” (you will need administrator rights here)
2.    Open applicationHost.config
3.    Find the section that showed up in the “config source” part of the error message page.  For me this has typically been “modules” or “handlers”
4.    Change the overrideModeDefault attribute to be “Allow”
5.    So the whole line now looks like:
<section name="modules" allowDefinition="MachineToApplication" overrideModeDefault="Allow" />
After saving the file, the page loaded up fine in my browser.

Reference

Wednesday, 25 July 2012