Posts

Showing posts from January, 2004

Force download file (ASP)

Any file on a web server can be downloaded to the client. The IUSR_MACHINENAME (or Everyone) account needs read access to that file for it be be downloaded. MDAC 2.5 or later is needed for this to work - http://www.microsoft.com/data/download_250rtm.htm JScript: // clear buffer Response.Buffer = true; Response.Clear(); // path to file var sFilePath = Server.MapPath("/path/to/file.pdf"); // attachment name (without extension), this will be what the name of the downloaded file will be var sAttachName = "attachmentname"; // remove spaces, else file may not download sAttachName = sAttachName.replace(/\s/g,""); // create filesystem object var oFSO = Server.CreateObject("Scripting.FileSystemObject"); // check if file exists if(!oFSO.FileExists(sFilePath)){ Response.Write('<strong>File does not exist. <a href="'+Request.ServerVariables("HTTP_REFERER")+'">Go back</s>.</strong>'); Response.E...

Convert Date to ISO (SQL Server)

To convert a date column into ISO format (YYYY-MM-DD) using SQL, the following code can be used: LEFT(CONVERT(char(10), DateColumn , 126), 10) AS DateFormatted Or using '/' as the seperator: REPLACE(LEFT(CONVERT(char(10), DateColumn , 126), 10), '-', '/') AS DateFormatted

Sizer - Change size of windows

Very useful freeware for resizing windows (for Microsoft Windows based PC's). Good for testing webpages at different resolutions without changing the screen resolution. Download from: http://www.brianapps.net/sizer.html (73kb exe installer, 17kb zip file)

Open Centered Popup Window (JavaScript)

The following script will open a centered popup window, maximum size 800 x 600. If the user has a resolution lower than 800 x 600, it will fill the screen. function openWin(page){ // width w = (screen.width>800) ? 800 : screen.width; // height h = (screen.height>600) ? 600 : screen.height; // left (centered) l = (screen.width-w)/2; // top (centered) t = (screen.height-h)/2; // open new window newWin = window.open(page,'newWin','left='+l+',top='+t+',width='+w+',height='+h); }

Manipulate URL QueryString (ASP JScript)

The following functions modify the QueryString in a URL by removing and adding parameters. // sURL = URL to append to, sParam = parameter name, sParamVal = parameter value function appendToURL(sURL,sParam,sParamVal){ // remove existing parameters sURL = removeFromURL(sURL,sParam) // remove ? if it is the last character on the URL sURL = sURL.replace(/\?$/,'') // generate the querystring (add '?' if querystring is blank, '&' if there are other parameters) sURL += ((sURL.indexOf("?") == -1)?"?":"&") + sParam + "=" + sParamVal; return sURL; } // sURL = URL to remove from, sParam = parameter to remove from URL function removeFromURL(sURL,sParam) { // where the querystring starts (i.e. where ? appears) var qStart = sURL.indexOf('?') + 1; // if ? is not in sURL (i.e. qStart = 0) or ? is at the end of sURL, then there are no parameters to remove if (qStart == 0 || qStart == sURL.length-1) return sURL; ...