Showing posts with label Asp. Show all posts
Showing posts with label Asp. Show all posts

Wednesday, November 4, 2009

Generate Sitemap using ASP

Sitemap is very important factor of web site , you can say its a list of pages of web site accessible to user. it Organize in hierarchical fashion. basically it helps the visitors and mostly on search engine bots to find the perticular page on you site. it improve seo of site , it works just like the dynamic access to site. basically sitemap in xml format.



Here i have created one sample application that can read xsl file and according to that it generate sitemap of your site.
on my Excel file i have place all the links of my sites.
now how to get this ,
1 .open your site say www.google.com
2. now on your web developer toolbar (Mozilla addon) on Information section > click view link information it will open open page and in that you can find all the site links
3. copy that on excel file and save it ,

now write application that read a data from excel and generate sitemap



< %

Const adOpenStatic = 3
Const adLockPessimistic = 2
Dim cnnExcel
Dim rstExcel
Dim I
Dim iCols

Set cnnExcel = Server.CreateObject("ADODB.Connection")
cnnExcel.Open "Driver={Microsoft Excel Driver (*.xls)};DriverId=790;Dbq="&Server.MapPath("1.xls")&";DefaultDir="&Server.MapPath(".")&";" Set rstExcel = Server.CreateObject("ADODB.Recordset")
rstExcel.Open "SELECT * FROM [Sheet1$]", cnnExcel
iCols = rstExcel.Fields.Count
rstExcel.MoveFirst
xmlData = ""
xmlData = xmlData&""
Do While Not rstExcel.EOF
xmlData = xmlData& ""
xmlData = xmlData& ""& rstExcel.Fields.Item(0).Value & "" & vbCrLf
xmlData = xmlData& "
"
rstExcel.MoveNext
Loop
xmlData = xmlData& "
"
Response.Write(xmlData)
rstExcel.Close
Set rstExcel = Nothing

cnnExcel.Close
Set cnnExcel = Nothing
% >

Run this file and view source code of this file , save view source file as a "Sitemap.xml"

Wednesday, August 5, 2009

ASP Format Date and Time

while coding on ASP we required date and time most of the time, how to get this is very basic and well known to the most of the Programmers, but how to get the only specific date , time in required format is a main task ,

for that we have inbuild function call FormatDateTime() .

now we very well knows if we want to get current date and time then we can use now()

<%dim TodayDnT
TodayDnT = now()
%>

if you want the Result of same then use <% Response.write(TodayDnT) %>
so it will return result as : - 8/5/2009 12:11 PM

now we have the option to format that
1. Using 0

<%
Response.write FormatDateTime(TodayDnT,0)
%>

Result : - 8/5/2009 12:11:10 PM


2. Using 1

<%
Response.write FormatDateTime(TodayDnT,1)
%>

Result :- Wednesday, August 12, 2009 (long date )


3. Using 2

<%
Response.write FormatDateTime(TodayDnT,2)
%>

Result: - 8/5/2009 (short date)


4. using 3

<%
Response.write FormatDateTime(TodayDnT,3)
%>

Result : - 12:11:10 PM (long time)


5. using 4

<%
Response.write FormatDateTime(TodayDnT,4)
%>

Result : - 11:10 (current time in 24 format (hh:mm)


If you want to change the Date and Time according to international location then
use session.lcid property

Ex : - <% session.lcid=1036 %>
which will set the Date n Time in French Format

here is the List of all the
International Location

Saturday, August 1, 2009

Loop through Session ,Application ,form Variable

In Classic asp sometime we need to retrieve all the Session Application and Request object variable, in this case we can use Loop through technique which will generate all the Session variable , application variable , and Request variable are used in current page do this need to simply put this line on your page

1.

<%
dim i
For Each i in Session.Contents
Response.Write(i & "<br />")
Next

dim i
For Each i in Session.StaticObjects
Response.Write(i & "<br />")
Next
%>

it will Display all the Session Contents / session staticobjets are used in current page .


2.

<%
dim i
For Each i in Application.Contents
Response.Write(i & "<br />")
Next
%>


this will iterate all the Application content are being used in current page.

3.

<%
for each x in Request.form
Response.Write("<br>" & x & " = " & Request.form(x))
next
%>


this will generate all the Request variable


4.


<%
for each name in Request.ServerVariables
Response.write ""&name &"-------------"& Request.ServerVariables(name) &"<br>"
Next
%>

it will loop with the all the Server Variable.

Monday, July 20, 2009

Filter User via IP

its a good technique to Restrict user to view your website , this task can be done with the help of checking of user's IP Address and match with our database and if user get found under
that IP then you can set Denied Access to them .

But in this case you need a Live IP Address database,
there are so many website are there they are provides free IP Address database range .

and with the help of that u can Denied user.

here are the List of free IP address database sites


Simply download that.

1. Create one IP check function
2. take user Ip address

in ASP : - Ip =Request.Servervariables("REMOTE_HOST")
in C# : - String ipAddress = (Request.ServerVariables["REMOTE_ADDR"]);

3. then check if user's Ip address is there in you'r database , depend on that
you can prevent user.


hope it will helps you,

Saturday, July 18, 2009

CountDown Timer

Hi , here is cool triks of CountDown timer, mostly its useful in website while validating time like online exam, date time , game countdown , and so many

Below is the code needed to display count down in HTML page using javascript.

You define container for the count down (either <span> or <div> tag) and the initial value, and the code updates the time automaticlly in the format HH:MM:SS

You can also control the style of the container using standard CSS, as demonstrated in the below and attached code.

To activate the count down in one of your existing pages you
have to follow two steps:

1. include the attached CountDown.js file with:


<script type="text/javascript" src="CountDown.js"> <script>


2. have such javascript in the section:



<script type="text/javascript">
window.onload=WindowLoad;
function WindowLoad(event) {
ActivateCountDown("CountDownPanel", 100);
}
</script>


where "CountDownPanel" is the ID of the container
(i.e. you should have <span> or <div> with this ID) and 100 is the time in seconds to be counted.

here is CountDown.js file -------------------------------

var _countDowncontainer=0;
var _currentSeconds=0;

function ActivateCountDown(strContainerID, initialValue) {
_countDowncontainer = document.getElementById(strContainerID);

if (!_countDowncontainer) {
alert("count down error: container does not exist: "+strContainerID+
"\nmake sure html element with this ID exists");
return;
}

SetCountdownText(initialValue);
window.setTimeout("CountDownTick()", 1000);
}

function CountDownTick() {
if (_currentSeconds <= 0) {
alert("your time has expired!");
return;
}

SetCountdownText(_currentSeconds-1);
window.setTimeout("CountDownTick()", 1000);
}

function SetCountdownText(seconds) {
//store:
_currentSeconds = seconds;

//get minutes:
var minutes=parseInt(seconds/60);

//shrink:
seconds = (seconds%60);

//get hours:
var hours=parseInt(minutes/60);

//shrink:
minutes = (minutes%60);

//build text:
var strText = AddZero(hours) + ":" + AddZero(minutes) + ":" + AddZero(seconds);

//apply:
_countDowncontainer.innerHTML = strText;
}

function AddZero(num) {
return ((num >= 0)&&(num < 10))?"0"+num:num+"";
}

Monday, June 29, 2009

Delete File in ASP

Yes, you can delete a file by using FileSystem Object in ASP


<%
// delete file
var FSO = Server.CreateObject("Scripting.FileSystemObject");
// get path to file
PathFile = Server.MapPath("/path/folder/deletefilename);
// if file exists, delete it
if(FSO.FileExists(PathFile)) FSO.DeleteFile(sPathToFile)
// file deleted

%>


like this way we can create , delete folder using FSO (file system object)
to know more about FSO system

Saturday, May 16, 2009

how to compress files using asp

how to compress files using asp

most of the time we require to compress file and save it to perticular localtion , or you can
use the for any purpose as u want .

for this we requires Server supporting WScript.Shell - most hosts won't allow this.

here u can get the download link , here u can specify either relative path or absolute path

before that please download this file, click here to download

-zipfile.asp
< % 

'---------------------------------------------------------
'CreateZipFile: function to create zip file at perticular location
'ZipPath - full path for the zip file, including the zip file name.
'arrFilesPath - array of the files to be zipped,
e.g. Array("C:\*.exe", "C:\foldername\*.*")
'NOTE: this code requires ZIP.EXE utility in the same location
' as this file.
'---------------------------------------------------------
Sub CreateZipFile(ZipPath, arrFilesPath)
Const PKZIP_FILE_NAME="zip.exe"
Dim strCommand, objShell, objFSO
Dim x

'first check zip.exe file is exists:
Set objFSO=Server.CreateObject("Scripting.FileSystemObject")
If Not(objFSO.FileExists(Server.MapPath(ZIP_FILE_NAME) )) Then
Set objFSO=Nothing
Err.Raise 20000, "Zip File Creator", "zip utility not found: "&Server.MapPath(ZIP_FILE_NAME)
End If

'delete current file:
If objFSO.FileExists(ZipPath) Then
objFSO.DeleteFile(ZipPath)
End If
Set objFSO=Nothing

'batch command:

strCommand=Server.MapPath(ZIP_FILE_NAME)&" -add "&ZipPath&" "
For x=0 To UBound(arrFilesPath)
strCommand=strCommand&arrFilesPath(x)
If x < UBound(arrFilesPath) Then strCommand=strCommand&" "
Next

'execute:
Set objShell=Server.CreateObject("WScript.Shell")
objShell.Run strCommand, 0, True 'wait!

'done.
Set objShell=Nothing
End Sub
%>

now u can call your CreateZipFile() function
-checkZipFile.asp


< % 

Call checkZipFile()

Sub checkZipFile()
'create zip and give link:
Call CreateZipFile(Server.MapPath("Testzip.zip"), Array(Server.MapPath("images")&"\*.*"))
Response.Write("click here download zip")
End Sub
%>
here u can get the download link , here u can specify either relative path or absoutate path

how to display records from an excel file

hi this is my first blog in this blogspot , hope it may help you ..

i have seen most of the time software people require to display records from an Microsoft Excel in an ASP. We could use SQL command while retreving data from an excel sheet. for the we know how to connect with sql

here is the sql connection string :

strConnection = "DBQ=" & Server.MapPath("nameofexcelfile.xls") & "; DRIVER={Microsoft Excel Driver (*.xls)};"

We will use a specific driver to connect to Excel files.
so for that we can use ODBC

An Example :

strConnection = "DBQ=" & Server.MapPath("nameofexcelfile.xls") & "; DRIVER={Microsoft Excel Driver (*.xls)};"

Set conn = Server.CreateObject("ADODB.Connection")
Set rss = Server.CreateObject("ADODB.Recordset")
cn.open strConnection


sql="select * from tablename;"

rss.Open sql, conn, adOpenStatic, adLockPessimistic


do while not rss.eof
response.write rss("Fieldname")
rss.movenext
loop

rss.close
Set rss = nothing
conn.close
Set conn = nothing


and now u can access you excel content in you are asp coding

thank you.