Wednesday, November 25, 2009

How to change color of scrollbar in browser

Changes the color of scrollbar and it will work in IE5+ .
put this class inside HEAD Tag.



HTML{

scrollbar-face-color:#75EA00;

scrollbar-arrow-color:brown;

scrollbar-track-color:#EEEEEE;

scrollbar-shadow-color:'';

scrollbar-highlight-color:'';

scrollbar-3dlight-color:'';

scrollbar-darkshadow-Color:'';

}

Note: Don't put a dot symbol before css class name means don't use like .HTML

Labels:

How to replace cusor by an image

Using CSS to change the cursor by an image. The image type must be .cur or .ani type to implement this.
write thses code in style tag.
BODY{

cursor:url("crosshair.cur");

}

Labels:

How to copy text to clipboard in javascript

If the user want to copy some content ,he have to select some content then right click ,then click copy.if u want in ur appplication that there will be a control onclick of which the content of controls for example textbox will copy to click board,then call a javascript function onclick that button
< input type="button" value="copy" onclick="CopyToClipboard();">

function CopyToClipboard()

{
var textboxVal = document.getElementById("txtCopy").value; //txtText id of a textbox
if( window.clipboardData && clipboardData.setData )
{
clipboardData.setData("Text", textboxVal);
}
else
{
alert("works only in IE4+");
}
}

Labels:

Thursday, November 19, 2009

How to search text and highlight the text that matches in a webpage.

Use the following function and pass the string to be searched in the function as parameter.


var n = 0;
function Findstring(searchstring)
{
  if (document.all)
  {
    var txt = window.document.body.createTextRange();//create a text range i.e all text in webpage

   for (i = 0; i <= n && (found = txt.findText(searchstring)) != false; i++)
   {

     txt.moveStart("character", 1);//move to next
     txt.moveEnd("textedit");//move to end
   }
   if (found)
   {
    txt.moveStart("character", -1);
    txt.findText(searchstring);
    txt.select();//hightlight the text
    txt.scrollIntoView();
    n++;

}
   else

{
  if (n > 0)
   {
    n = 0;
    Findstring(searchstring);

   }
   else
   {
    alert("Sorry, we couldn't find.Try again");

   }

  }

 }
  return false;
}
It will highlight the string if any matched case will be found .It works in IE4+.

Labels:

How to encode or decode password in c# with asp.net

How to encode a password:

private string base64Encode(string sData)
{
try
{

byte[] encData_byte = new byte[sData.Length];
encData_byte = System.Text.Encoding.UTF8.GetBytes(sData);
string encodedData = Convert.ToBase64String(encData_byte);
return encodedData;

}
catch(Exception ex)
{
throw new Exception("Error in base64Encode" + ex.Message);
}
}

How to decode it

public string base64Decode(string sData)
{

System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
System.Text.Decoder utf8Decode = encoder.GetDecoder();
byte[] todecode_byte = Convert.FromBase64String(sData);
int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);

char[] decoded_char = new char[charCount];
utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
string result = new String(decoded_char);
return result;

}

How to use it:

Pass the passwd at the time of registration process to that function and save it in database .at the time of login retrive it and decode it and compare with password entered by user,if satisfy then redirect to another page else will be in correct email or userid or password.

calling function for encode

string pwed = base64encode(val);

calling function for decode

string pwed = base64Decode(val);

Labels:

Wednesday, November 18, 2009

Export dataset to CSV file using C#

Create a dataset

Example:
string strReferral = //your query

DataSet dsPe = SqlHelper.ExecuteDataset(new Connection().GetCon, CommandType.Text, strReferral);

//pass the dataset as argument to this function
ExportDataSet(dsPe);

public void ExportDataSet(DataSet ds)
{
string filename = "MyExcelFile.xls";
HttpResponse response = HttpContext.Current.Response;
response.Clear();
response.ContentType = "application/vnd.ms-excel";
response.AddHeader("Content-Disposition", "attachment;filename=\"" + filename + "\"");
}

Labels: ,

How to create a new event log using c#

private void WriteToEventLog(string message)
{
string newSource = "NewSource";
EventLog eventLog = new EventLog();
if (!EventLog.SourceExists(newSource))
{
EventLog.CreateEventSource(newSource, newSource);
}
eventLog.Source = newSource;
eventLog.EnableRaisingEvents = true;
eventLog.WriteEntry(message);
}

Call above method and pass the message

WriteToEventLog("This is the message that I want to show");

Then go to control panel ->Administrative tools -> Event Viewer You can view the new event log and click on that event log you can Information and click on the information to view the message.

Labels: ,

How to download image programmatically from remote location using c#


Use this code to download image from remote location using c#

MemoryStream stream = new MemoryStream();
byte[] imagetoUpload;
string imageName = string.Empty;
string imgUrl = string.Empty;
System.Net.WebClient wc = new System.Net.WebClient();
imgUrl = "http://www.google.co.in/logos/boombah_chamki-hp.gif ";
imagetoUpload = wc.DownloadData(imgUrl);
imageName = imgUrl.Substring(imgUrl.LastIndexOf("/") + 1);
stream.Write(imagetoUpload, 0, imagetoUpload.Length);
Bitmap bmp = new Bitmap(stream);
bmp.Save(@"D:\" + imageName);

Namespace required:

using System.IO;
using System.Drawing;

Thanks,
Abhay

Labels:

How to add a flash movie to aspx page

The following code will embedded a flash movie in your aspx page

Just change the param value in param tag and Src attribute in embed tag according to your need.

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="name" 
width="468" codebase="http://active.macromedia.com/flash4
/cabs/swflash.cab#version=4,0,0,0" height="60"> <param 
value="http://www.mywebsite.com/images/mf-movie.swf" name="movie"/>
<param value="high" name="quality"/> <param value="transparent" 
name="wmode"/> <embed pluginspage="http://www.macromedia.com/shockwave
/download/index.cgi?P1_Prod_Version=ShockwaveFlash" quality="high" 
type="application/x-shockwave-flash" height="100"
src="http://www.mywebsite.com/images/mf-movie.swf" width="468" 
wmode="transparent" name="name"> </embed> </object>

Labels: