solution for Space is shown as %2520 insted of %20 in link url

HI Friends

Today i would like to discuss one of the issues which took 3 days of my time in searching around google so today i am presenting both problem and solution

the problem is
my dotnet code was generaing dynamic html in code behind and among them there exist a link with url pointing to some file example

a href=”//fileserver/foldername/abc 10.pdf”

so here my browser was intended to show like this when a cursor is placed on link

a href=”//fileserver/foldername/abc%2010.pdf”

here as you all know browser shows space as %20

but my browser was showing %2520 insted of %20 which was causing the issue

the link was like this when issue exist
a href=”//fileserver/foldername/abc%252010.pdf”
where as browser was expecting
a href=”//fileserver/foldername/abc%2010.pdf”

so was searching about the issue came to know several people answers like placing Runat= server in link is the solution or problem with file server or problem with browser
hmmm ultimately one fine day i got the solutionūüôā the solution is
just append <b>”file:///”</b> before the path this will solve your problem

so as solution i placed like this

a href=”file:///fileserver/foldername/abc 10.pdf” in code behind and browser was now showing correctly as

href=”//fileserver/foldername/abc%2010.pdf”
Just posting it as you people should not waste your time searching for this as one of the guy on earth found it and ready to share this to avoid time waste

cheers
Santosh Kakani

 

Posted in Coding | Tagged , , , | Leave a comment

Open files with no extension using notepad by default in windows 8/7 and xp

i wanted to open all files having no extension with notepad in windows 8/7 and xp

for that please open one notepad and save the following lines as it is and 

rename that file as abcd.reg and execute that after executing it this will work 

you can check it after clicking on the file with no extension 

for example files with no extension will exist in c:\Windows\System32\drivers\etc like Host etc.,

 

—————————————————-

Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\.]
@=””

[HKEY_CLASSES_ROOT\.\shell]

[HKEY_CLASSES_ROOT\.\shell\open]

[HKEY_CLASSES_ROOT\.\shell\open\command]
@=”notepad.exe %1″

—————————————————-

Posted in Uncategorized | Tagged , | Leave a comment

Programe to Confirm Leaving of page using javaScript

for example if you have a scenario that to display confirm leaving when ever user is leaving the page by closing browser or by clicking on any part of other page lie, clicking on buttons or Links

for that we need to write one simple javascript function

var isChange =1;

function ConfirmLeaving()

{

            if(isChange==0)
               {
¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† return “All the entered information will be lost. Do you wish to continue?”;
               }
               return;

}

in Body tag call a function on beforeunload¬† as onbeforeunload=”return confirmleaving();”

 

so here when ever a user try’s to navigate from the page or perform operations for postback this event is fired

suppose if you want any clicking on some button named “Button1” should not get this message you can simply place in onclick() function to set isChange=1 so that the above written condition will satisfy and which wont show the popup

you can place isChange for div for example

if i have a div which have so many buttons and clicking on those many buttons should not give this confirmation message so for this i need to set my flag isChange when ever user mouseout or mousein from the div like this

<div¬† onmouseover=”isChange = 1″ onmouseout=”isChange = 0″ >

——–

——–

——–

</div>

when ever the user try’s to click outside the div he will get confirmation message and when user click’s inside div confirmation is not fired this is achived using a flagūüôā

 

Have a Happy coding

regards

Santosh Kakani

 

Posted in Uncategorized | Tagged , | Leave a comment

Compare 2 ArrayLists using C# and tell wether they are same or not

usefull method to compare 2 ArrayLists

private bool CompareArrayLists(ArrayList List1, ArrayList List2)
    {
        if (List1.Count != List2.Count)
            return false;

        for (int i = 0; i < List1.Count; i++)
        {
            if (!List1[i].Equals(List2[i]))
                return false;
        }
        return true;
    }

 

Posted in Uncategorized | Tagged , | Leave a comment

Upload .csv file to Codebehind and Convert it to Dataset using C#

HI friends

this example is going to teach you how to upload a .csv file using file upload control and how to Convert the content of .csv file into Dataset so that this Dataset can be used further in Programe

 

need to place button in page and write Code in Upload_Click() as

 

¬†FileUpload1.SaveAs(“D:\\Text.csv”);

        DataTable dtCVSData = null;
        using (OleDbDataAdapter oleDA = new OleDbDataAdapter())
        {
¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† using (OleDbConnection oleCon = new OleDbConnection(“Provider=Microsoft.Jet.OLEDB.4.0;Data Source=” + filePath + “;Extended Properties=\”Text;HDR=Yes;FMT=Delimited;\””))
            {
¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† using (OleDbCommand oleCmd = new OleDbCommand(“SELECT * FROM [” + fileName + “]”, oleCon))
                {
                    oleCon.Open();
                    oleDA.SelectCommand = oleCmd;
                    dtCVSData = new DataTable();
                    oleDA.Fill(dtCVSData);
                }
            }
        }

 

Finally the content of csv file is on dtCVSData Dataset

you can store it in session or you can utilize the same

thats it

 

Posted in Uncategorized | Tagged , | Leave a comment

Convert string CCYYMMDD to Date Time format using C#

Hi Friends

Today when i was Writing a Programe to upload .csv file to server in which i encountered a small problem that is the user was entering date in string format in .csv file as CCYYMMDD(20140130) format so when i was converting this string to date time format it was throwing exception so finally got the solution for the same.

here i wrote one method which will validate the data entered in string CCYYMMdd format and if it is valid then it is going to convert this string to date time format

string datefrmt = “20140130”; // this is correct format as it is in CCYYMMdd format

string datefrmt =”2014/01/30″; // this is not in correct format

if(ValidateDate(datefrmt)){

Console.Write(‘this is Valid date format’);

}

else

{

Console.Write(‘this is invalid date format);

}

 

public bool ValidateDate(string date)
{
try
{
System.Globalization.DateTimeFormatInfo dtfi = new  System.Globalization.DateTimeFormatInfo();
dtfi.ShortDatePattern = “yyyyMMdd”;
DateTime dt = DateTime.ParseExact(date, “d”, dtfi);
}
catch(Exception){
return false;
}
return true;
}

 

Posted in Uncategorized | Tagged , | Leave a comment

Adding Ascx controls Dynamically using asp.net

Hi friends you can add User controls dynamically using the following code

if there exists a Student page and you need to add a user control into this page when button1 is clicked

so you should write code like this for button click

private void button1_click(sender object, Eventargs args)
{

Student setproject = (Student)LoadControl(“Include/Product.ascx”);

//or
this.Controls.Add(Controlid)
}

Posted in Uncategorized | Leave a comment