Part 2: LINQ Tips & Tricks [Things to get you started efficiently]

This blog entry is in continuation with my first post on Part 1: LINQ Tips & Tricks [Things to get you started efficiently]

Continuing to share some other important tips that you can take care of while developing with LINQ.

[9] Loading Options while working with tables in Relationships

You always need to struggle for performance as a LINQ Developer; perhaps because to understand better how internal mechanism works.

using (BEDataContext context = new BEDataContext())
{
    var customers = from cust in context.Customers
                    select cust;
    foreach (var customer in customer)
        Response.Write(customer.CustomerAddresses.Count().ToString());
}

Read More…

Part 1: LINQ Tips & Tricks [Things to get you started efficiently]

While my development with LINQ I got around some helps, links, small tips and tricks which makes life much easier, improves query formulation capabilities and speedup the program execute performance. Here I am sharing some of the tips I found as a LINQ Developer.

[1] Use the var Keyword When Confused

Use var keyword as return type especially when you are capturing sequence of anonymous classes. For example, joining of 2 tables and retrieving a sequence of records containing (some/few) fields of both the tables. I appreciate the developers who understand and know exactly what data type is contained in the sequence they are retrieving. But, anyhow you get stuck and don’t know the sequence IEnumerable<T> holds what data type T; then var is the good choice.

 

Read More…

How to create DotNetNuke(DNN) Scheduler

Did you ever need to write disconnected process which should be run at a defined interval time? Commonly, when we are in such need – we use to write window service which is based on some timer mechanism where we set some interval for the timer and in its elapsed method we execute the process we want to run at defined interval.

When you work with DotNetNuke and you come across with such functionality that need tobe implemented – you can consider creating “DotNetNuke Scheduler”. While creating a DNN Scheduler – you are actually creating a simple class library which would be built and hosted in the DNN Schedule environment to be executed at the defined interval time.

The possible scenario in which one need to look at such schedule functionality is:
[1] You may need to send some set of fixed newletter everyday at defiend time to your customers.
[2] You may need to read some of third party product feed to read regular update and modify your product database.
[3] You may need to send some system generated reports to your third party vendor at some regular intervals.

Read More…

DotNetNuke – Where do you write your application CSS?

after Long time…. back in the community finally… :)

I was working in DNN application since I used to add css classes as and when I need to add which are related to specific my custom dnn modules. Initially, I used to add those classes in MinimulExtropy skin css file. But, as time goes.. it grows in size and there are situations when skin tend to change everytime (because some skin related issues or client didnt like it). Sp, everytime when any skin got changed I need to manually “copy” and “paste” those application (related to custom desktop modules) css classes in to the targetted skin folder’s css files. Because, somehow AFAIK dnn doesn’t support App_Theme folder or .skin files (because of its skin architecture).

Read More…

File download problem: filename with spaces truncated in FF and replaced by underscore in IE

This is a mere note to remember for future rather than a blog entry. While I am working on code to download file from server. I write below code:

        {
            int ChunkSize = 10000;
            string sFileFullPath = Server.MapPath("New Text Document.txt");
            System.IO.FileInfo toDownload = new System.IO.FileInfo(sFileFullPath);
            if (System.IO.File.Exists(sFileFullPath))
            {
                Response.Clear();
                using (FileStream iStream = System.IO.File.OpenRead(sFileFullPath))
                {                  
                    long dataLengthToRead = iStream.Length;
                    Byte[] buffer = new Byte[dataLengthToRead];                   
                    Response.ContentType = "application/octet-stream";                   
                    Response.AddHeader("Content-Disposition", "attachment; filename=" + filename);                                                          
                    while (ChunkSize > 0 && Response.IsClientConnected)
                    {
                        if (ChunkSize > dataLengthToRead)
                        {
                            ChunkSize = int.Parse(dataLengthToRead.ToString());
                        }                      
                        int lengthRead = iStream.Read(buffer, 0, ChunkSize);
                        Response.OutputStream.Write(buffer, 0, lengthRead);
                        Response.Flush();
                        dataLengthToRead = dataLengthToRead - lengthRead;
                    }
                }
                Response.Close();
                Response.End();
            }
            else
            {
                this.Page.ClientScript.RegisterStartupScript(GetType(), "ShowMessage", "<script language='javascript'>alert('No Files Available');</script>");
            }
        }

When I ran the application I found that the file which I need to download was containing spaces in its name like “New Text Document.txt”.

The problem is:

Read More

OnKeyPress event – event.keyCode and event.which (validating for numarics)

I am trying to validate textbox for numeric entry, while I added this code to accomplish in page_load event:

textbox.Attributes.Add(“onkeypress”, “return (window.event.keyCode == 45 || window.event.keyCode == 13 || window.event.keyCode == 8 || window.event.keyCode == 9 || window.event.keyCode == 189 || window.event.keyCode == 109 || (window.event.keyCode >= 48 && window.event.keyCode <= 58) )”);

It worked fine in IE7 and IE8, but it didnt work for FF though. A bit googling gave me conclusion that….

Read More

DotNetNuke – Invalid URI: The hostname could not be parsed error

Generally, I would like to blog post any errors that I face duing development. So that it would be helpful to me for my future reference in case I face it again as well as for the sake of any blog readers who may face same error.

Talking about the error “Invalid URI: The hostname could not be parsed error”: This the same and common error I faced previously some times back and which I also stated in my blog entry DotNetNuke – Invalid URI: The hostname could not be parsed

This time I was about to run a DNN application which is configured from my local server to live application server when I faced the same error. I tried the same work-a-round which I stated in my previous blog entry. But, this time that didn’t work even after investing some hrs investigation.

Read More

Issue: Session Auto Expire Earlier in ASP.NET

There are possible work-a-round and solution to work upon “session auto expire earlier” issue. Setting SessionTimeOut in web.config would no be enough to have your session persist for the said time or you want it to be.

Here I have found some solution which worked in my case:

Read More

Core ASP.NET Card, Get it Free

Core ASP.NET Card

Core ASP.NET: This Refcard summarizes the most commonly used core functions and controls in ASP.NET

Try it! Its free but requires registration.

Read More

Create PDF files on-the-fly in ASP.NET (Using Crystal Report!)

Here is another requirement (perhaps a common requirement!) I needed to implement in one of on-going project website application. I needed to generate a PDF file as output from the inputs entered by end-user in a form. On Completing the form, end-user should be able to download a PDF file of what they have given the inputs in the form.

I need to generate PDF file in a given format and force the download dialog to let the user save generated PDF save on their/client machine.

I tried searching any free :) third party dlls which would help me to generate PDF files on-the-fly. Things I tried:

[1] Tried searching almost third party tools/dlls including Siberix PDF Library , PDF Vision .Net etc etc, which are having similar functionality. But not FREE :(

[2] Tried with iTextSharp – Tutorial and PDFsharp – Download PDFsharp Version 1.20 These dlls/libraries are totally free and really interesting to work with. All we need to do is define elements like HTML and add those elements to PDF document object which then finally generated as PDF document. But, this is the problem for me as I am having a huge PDF file needed to generate as output and it would required a loot of time to code for a document by placing line by line cells, TR and TD, Tables and background, Border colors, images etc. and most of all is annoying Texts to be placed in those elements with proper fonts, colors and padding/alignment.

At last after wasting time in googling and on free tools/libraries, I got an idea to create PDF on-the-fly. I was thinking of creating PDF files dynamically and I created it smoothly with out too much work and code.

This is how it goes:

Read More

Follow

Get every new post delivered to your Inbox.