האובייקט ADODM.Stream מאפשר שליחת קבצים באופן בינארי אל הדפדפן. כשאתה משתמש בשיטת ה – BinaryWrite אתה בעצם גורם להורדת הקובץ. כל שעליך לעשות זה להזין את סוג התשובה שאתה רוצה לקבל:
Response.ContentType = "application/x-msexcel";
במקרה הזה, כפי שאפשר לראות, התשובה תיהיה קובץ EXCEL (וגם את תקשר אותו לקובץ אחר, לדוגמא ZIP, הוא עדיין ישמור לך אותו כ EXCEL).
1 תשובות
האובייקט ADODM.Stream מאפשר שליחת קבצים באופן בינארי אל הדפדפן. כשאתה משתמש בשיטת ה – BinaryWrite אתה בעצם גורם להורדת הקובץ. כל שעליך לעשות זה להזין את סוג התשובה שאתה רוצה לקבל:
Response.ContentType = "application/x-msexcel";
במקרה הזה, כפי שאפשר לראות, התשובה תיהיה קובץ EXCEL (וגם את תקשר אותו לקובץ אחר, לדוגמא ZIP, הוא עדיין ישמור לך אותו כ EXCEL).
הקוד המלא:
JS:
Response.ContentType = "application/x-msexcel";
var strFilePath;
strFilePath = Server.MapPath("x.xls");
var objStream = Server.CreateObject("ADODB.Stream");
objStream.Open();
objStream.Type = 1;
objStream.LoadFromFile(strFilePath)
Response.BinaryWrite(objStream.Read);
objStream.Close();
objStream = null
delete objStream;
VBS:
Response.ContentType = "application/x-msexcel"
Dim strFilePath
strFilePath = Server.MapPath("x.xls")
Dim objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
objStream.Type = 1
objStream.LoadFromFile strFilePath
Response.BinaryWrite objStream.Read
objStream.Close
Set objStrem = nothing
סוגי תשובות נפוצות:
<% Response.ContentType = "text/HTML" %>
<% Response.ContentType = "text/XML" %>
<% Response.ContentType = "text/XSL" %>
<% Response.ContentType = "text/JavaScript" %>
<% Response.ContentType = "application/xhtml+xml" %>
<% Response.ContentType = "application/x-cdf" %>
<% Response.ContentType = "image/GIF" %>
<% Response.ContentType = "image/JPEG" %>
<% Response.ContentType = "image/PNG" %>
<% Response.ContentType = "text/plain" %>
<% Response.ContentType = "application/vnd.ms-powerpoint" %>
<% Response.ContentType = "application/x-msexcel" %>