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

Saturday, 21 July 2012

count occurrence of word in sentences JavaScript


       var temp = "This is a string.";

        // the g in the regular expression says to search the whole string
        // rather than just find the first occurrence
        var count = temp.match(/is/g);

        alert(count.length);
       
          (Or)
          alert(temp .split("is").length - 1);


       Result:
       1





Friday, 20 July 2012

SQL SERVER – Switch Between Two Parenthesis using Shortcut CTRL+]


SELECT *
FROM (SELECT *
FROM (SELECT *
FROM (SELECT *
FROM tbl_emp)a)b)c

Now press CTRL+] and you will see that it jumps from b to the opening parenthesis.

SELECT *
FROM (SELECT *
FROM (SELECT *
FROM (SELECT *
FROM tbl_emp)a)b)c

You can once again press CTRL+] and it will jump back to parenthesis after b.





CTRL+SHIFT+] Shortcut to Select Code Between Two Parenthesis

CTRL+SHIFT + ]   has selected the code between two corresponding parentheses.

SELECT *
FROM (SELECT *
FROM (SELECT *
FROM (SELECT *
FROM tbl_emp)a)b)c






Never regret. If it’s good, it’s wonderful. If it’s bad, it’s experience.




Monday, 16 July 2012

Error - Operation is not valid due to the current state of the object


Whenever a postback is done, this error occurs when form fields are very large in number. The stack trace is:
at System.Web.HttpValueCollection.ThrowIfMaxHttpCollectionKeysExceeded() at System.Web.HttpValueCollection.FillFromEncodedBytes(Byte[] bytes, Encoding encoding) at System.Web.HttpRequest.FillInFormCollection()
By default, the maximum value of MaxHttpCollection is 1000.
To solve this error, increase the MaxHttpCollection value. Try adding the following setting in yourweb.config's <appsettings> block.
  <appSettings>
      <add key="aspnet:MaxHttpCollectionKeys" value="3000" />
  </appSettings>
It can solve your problem. If you have very large records on your page, say 600 records in a grid, and you click on Submit, then increase the value of MaxHttpCollection.
Then change value 2000 to 5000 and test again. It will be resolved. :-)

Tuesday, 10 July 2012

determine if the OS is 32 bit or 64 bit in c#



int getOSArchitecture()
        {
            string pa = Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE");
            return ((String.IsNullOrEmpty(pa) || String.Compare(pa, 0, "x86", 0, 3, true) == 0) ? 32 : 64);
        }


Monday, 9 July 2012

check if a string contains small letter in sql


select patindex('%[a-z]%'    COLLATE Latin1_General_BIN,'test')

select patindex( '%es%'    COLLATE Latin1_General_BIN,'Test')

Sunday, 8 July 2012

sql - Check length of a string


Length of VARCHAR fields the function LEN(varcharfield) is useful.
Length of TEXT fields the function is DATALENGTH(textfield). Len will not work for text field.
Example:
SELECT LEN(yourvarcharfield) AS VarcharFieldSize
SELECT DATALENGTH(yourtextfield) AS TEXTFieldSize

SQL - check if a string has uppercase / lowercase characters


DECLARE @myString NVARCHAR(200) -- The length of the NVARCHAR is mandatory, otherwise it is not clear why but it is not working
SET @myString = 'ExTremeDev.blogSpot.com23'

IF @myString = LOWER(@myString) COLLATE Latin1_General_CS_AI
BEGIN
  PRINT '- The string must contain at least one uppercase character.'
END

IF @myString = UPPER(@myString) COLLATE Latin1_General_CS_AI
BEGIN
  PRINT '- The string must contain at least one lowercase character.'
END

IF PATINDEX('%[0-9]%',@myString) = 0
BEGIN
  PRINT '- The string must contain at least one numeric character.'
END

Thursday, 5 July 2012

Channel timeout exception


Notice that you do not call close on the proxy - this means that the service will be maintaining a session on behalf of the client (assuming you are using broadly the default settings of the WSHttpBinding)

add a call to requestClient.Close() after calling the Execute operation

Wednesday, 4 July 2012

Count No of users- session Count -global.asax



    void Application_Start(object sender, EventArgs e)
    {
        // Code that runs on application startup
        Application["count"] = 0;
    }
   
    void Application_End(object sender, EventArgs e)
    {
        //  Code that runs on application shutdown
        Application["count"] = (int)Application["count"] - 1;
    }
       

Sunday, 1 July 2012

highlight-words-jquery-ui-autocomplete and catcomplete

<script type="text/javascript">
    $("#textbox").autocomplete({
        source: function (request, response) {
            $.ajax({
                url: "search.php",
                dataType: "json",
                data: request,
                success: function (data) {

                    var regex = new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + request.term.replace(/([\^\$\(\)\[\]\{\}\*\.\+\?\|\\])/gi, "\\$1") + ")(?![^<>]*>)(?![^&;]+;)", "gi");
                    var result = $.map(data, function (value) {
                        return value.replace(regex, "<b>$1</b>");
                    });
                    response(result);
                }
            });
        }
    });
</script>