Wednesday, January 19, 2011

Read XML from network/ static ip with credentials

When you wants to read/get xml from network or from static ip on web then you would required to validate your credentials for that. below is example from which you can learn that how to access xml from another system with validating credentials.

public XmlDocument getXML()
{
string fileName = "123.22.23.2//folderName//xmlName.xml";
        Uri myUrl = new Uri("file://" + fileName);

        FileWebRequest request = (FileWebRequest)WebRequest.Create(myUrl);
        byte[] authBytes = Encoding.UTF8.GetBytes(("myuserName" + ":" + "MyPassword").ToCharArray());
        request.Headers["Authorization"] = "Basic " + Convert.ToBase64String(authBytes);
        WebResponse response = request.GetResponse();
        Stream strm = response.GetResponseStream();
        StreamReader sr = new StreamReader(strm, System.Text.Encoding.Default);
        XmlDocument xdoc = new XmlDocument();
        xdoc.LoadXml(sr.ReadToEnd());
        return xdoc;
}
Read More

Tuesday, January 18, 2011

Convert string to array list or convert string array to array list

Convert string to array list

Convert string array to array list


To convert string to array list :

  ArrayList mylist= new ArrayList( mystring.Split(','));


To convert string array to array list :

  ArrayList mylist= new ArrayList(mystringarray);
Read More

How to get url without paramters/query string

Many of times we just wants exact url of our page without parameters. to get it you can use below code:

Request.Url.GetLeftPart(UriPartial.Path)

Solution By: Rajesh Rolen
Read More

Monday, January 17, 2011

Best overloaded function for arrayList.IndexOF

This is the best function which you can use for IndexOf Functionality . it provides lots of extra functionality.

  public int ArrayIndexOf(string[] arr, string search, int startIndex, bool caseSensitive, bool exactMatch)
    {
        // if the search is case-sensitive and it runs against exact matches only,
        //  use the standard Array.IndexOf function
        if (caseSensitive & exactMatch)
        {
            return Array.IndexOf(arr, search, startIndex);
        }

        if (!caseSensitive)
            search = search.ToLower();

        int lastIndex = arr.GetUpperBound(0);
        int i = 0;
        for (i = startIndex; i <= lastIndex; i++)
        {
            string currElem = arr[i];
            // if the search is not case-sensitive, convert everything to lower-case
            if (!caseSensitive)
                currElem = currElem.ToLower();
            if (exactMatch)
            {
                if (search == currElem)
                    return i;
            }
            else
            {
                // if partial matches are ok, use the String.IndexOf function,
                //  and return the
                // current index if a partial match is found
                int j = currElem.IndexOf(search);
                if (j > -1)
                    return i;
            }
        }

        // if we get here, no element matches the search options, so return -1
        return -1;
    }

Read More

The best overloaded method match for 'string.Join(string, string[])' has some invalid arguments

While trying to convert arraylist to string with delimiter separated you would encounter this error .
to get rid from it try this:

string str = string.Join(",",(string[]) srchTags.ToArray (typeof(String)));

Solution By: Rajesh Rolen
Read More

Friday, January 7, 2011

what is the name of the iis process in windows 7 or I am not able to find IIS process in windows 7

if you are using visual studio in windows 7 and you wants to attach your asp.net code with worker process "w3wp.exe". follow below steps.

press: ctrl + alt + P
you will not able to find this process directly there so to get that process in list you will have to check the check box "Show processes in all sessions".
now if you not started your visual studio with admin rights then it will ask you to save and restart visual studio with admin rights. click it and it will restart visual studio with admin right and its done.
now again press: ctrl + alt + P and check checkBOx "Show processes in all sessions" and you can now view "w3wp.exe" process. so just select it and attach..


Solution By: Rajesh Rolen
Read More

Thursday, January 6, 2011

HTTP Error 500.23 - Internal Server Error An ASP.NET setting has been detected that does not apply in Integrated managed pipeline mode.

HTTP Error 500.23 - Internal Server Error
An ASP.NET setting has been detected that does not apply in Integrated managed pipeline mode.

You gets this error mostly in windows 7 when you wants to run you web site using virtual directory on IIS.

This solution is :Open IIS manager, and go to the Application Pool for your site.
Change the properties of the application pool from "Integrated" to "Classic".

Solution By: Rajesh Rolen
Read More

Wednesday, January 5, 2011

How to invoke garbage collector programatically

In applications with significant memory requirements, you can force garbage collection by invoking the GC.Collect method from the program. This is not recommended and should be used only in extreme cases.

Solution By: Rajesh Rolen
Read More

How many type of caching available in asp.net

ASP.NET supports three types of caching for Web-based applications:

Page Level Caching (called Output Caching)
Page Fragment Caching (often called Partial-Page Output Caching)
Programmatic or Data Caching

Solution By:Rajesh Rolen
Read More

Can we call Finalize()?

ofcourse we can call finalize method, and System.gc() is also made for requesting the garbage collection. although System.gc() do not guarantee the garbage collection.

Solution By: Rajesh Rolen
Read More

Is it possible to overload static constructor

No its not.

The name of a static constructor must be the name of the class and even they don't have any return type. The keyword static is used to differentiate the static constructor from the normal constructors. The static constructor can't take any arguments. That means there is only one form of static constructor, without any arguments. In other way it is not possible to overload a static constructor.

Solution By: Rajesh Rolen
Read More

Types of Triggers

There are two type of triggers:- Row-level and statement-level triggers. A row-level trigger fires once for each row that is affected by a triggering event. For example, if deletion is defined as a triggering event on a table and a single DELETE command is issued that deletes five rows from the table, then the trigger will fire five times, once for each row.

In contrast, a statement-level trigger fires once per triggering statement regardless of the number of rows affected by the triggering event. In the prior example of a single DELETE command deleting five rows, a statement-level trigger would fire only once.

The sequence of actions can be defined regarding whether the trigger code block is executed before or after the triggering statement, itself, in the case of statement-level triggers; or before or after each row is affected by the triggering statement in the case of row-level triggers.

In a before row-level trigger, the trigger code block is executed before the triggering action is carried out on each affected row. In a before statement-level trigger, the trigger code block is executed before the action of the triggering statement is carried out.

In an after row-level trigger, the trigger code block is executed after the triggering action is carried out on each affected row. In an after statement-level trigger, the trigger code block is executed after the action of the triggering statement is carried out.

Solution By: Rajesh Rolen
Read More

Tuesday, January 4, 2011

Get File size in javascript

function A()
 {
 var oas = new ActiveXObject("Scripting.FileSystemObject");
 var d = document.a.b.value;
 var e = oas.getFile(d);
 var f = e.size;
 alert(f + " bytes");
 }
  
 
 <form name="a" >
  <input type="file" name="b" >
  <input type="button" name="c" value="SIZE" onClick="A();" >
  </form >
  </body >

Read More

Monday, January 3, 2011

Run URL from desktop application

You can run/call URL and get response from desktop application

  private static string GetPageContent(string FullUri)
        {
            HttpWebRequest Request = default(HttpWebRequest);
            StreamReader ResponseReader = default(StreamReader);

            Request = (HttpWebRequest)WebRequest.Create(FullUri);
           
            ResponseReader = new StreamReader(Request.GetResponse().GetResponseStream());

            return ResponseReader.ReadToEnd();
        }

solution by: Rajesh Rolen
Read More
Powered By Blogger · Designed By Seo Blogger Templates