January 09, 2014

Best way to get Query string from url in SharePoint / Asp .Net / webApps

The easiest and well know way is to Request.QueryString[“name”]; but many times to get null exception we should check query string and return in appropriate format. Below I have created a private int variable and protected property of it. You can have a look on below code.

protected int ItemID
                if (Request.QueryString["itemId"] != null && Request.QueryString["itemId"].Length > 0)
                    return Convert.ToInt32(Request.QueryString["itemId"]);
                else return 0;

You can Share your findings or issue or Discussion below.

Praveen Pandit

No comments:

Post a Comment