paradise_wolf
03-16-2007, 12:53 PM
The usual code for downloading files allows the customer
to choose which folder ( in his computer ) he wants the
application to download to :
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
FileStream MyFileStream =
new FileStream(@"E:\X-102.pdf", FileMode.Open);
long FileSize;
FileSize = MyFileStream.Length;
byte[] Buffer = new byte[(int)FileSize];
MyFileStream.Read(Buffer, 0, (int)MyFileStream.Length);
MyFileStream.Close();
Response.ContentType = "application/pdf";
Response.AddHeader
("content-disposition", "attachment; filename= X-102.pdf ");
Response.BinaryWrite(Buffer);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
But the problem with this code is that you cannot
know if the customer finished successfully the
download and then use it as flag to trigger other
functionalities.
I have an alternative code for downloading a file that
allows me to control the download process and even
display it through a progress bar.
But it lacks the capability to allow the customer to
browse his computer and locate a convenient folder
to download the file like the first method.
I am building a web site where some customers, after
having logged in with special privileges, they could
then access a special page where they would be able
to download pdf files.
I would like to give them the capacity to choose
where ( which folder ) to download the pdf file in
their computers.
I wanted to use the following javascript code for
this purpose:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<script language=javascript>
<!--
function GetDownloadPath()
{
var frm = document.forms[0];
var Shell = new ActiveXObject("Shell.Application");
var Folder = new Object;
Folder = Shell.BrowseForFolder
(0, "Choose a download folder", 0);
var FolderItem = new Object;
FolderItem = Folder.Items().Item();
}
-->
</script>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
But someone told me that it only works on IE –and-
additionally, this code only works when it runs from
within a web site whose URL address starts with
“https” instead of “http”. Furthermore, it has to be
listed within “Trusted Sites” in the customer’s
IE Security settings and his computer should enable
ActiveX controls.
So, it seems that this method is a bit tricky and it
would alienate customers who either have different
internet browsers or do not enable ActiveX
controls in their computers.
Another option is to set my application with a
default path “C:\” assuming that every customer
would have this basic drive and add a TextBox
control where the customer could type an
alternative path. But then I would need a method
to verify if the customer typed a correct path.
Please I need the opinion of the experts to
suggest me which one is the best method or
even suggest me a better one.
to choose which folder ( in his computer ) he wants the
application to download to :
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
FileStream MyFileStream =
new FileStream(@"E:\X-102.pdf", FileMode.Open);
long FileSize;
FileSize = MyFileStream.Length;
byte[] Buffer = new byte[(int)FileSize];
MyFileStream.Read(Buffer, 0, (int)MyFileStream.Length);
MyFileStream.Close();
Response.ContentType = "application/pdf";
Response.AddHeader
("content-disposition", "attachment; filename= X-102.pdf ");
Response.BinaryWrite(Buffer);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
But the problem with this code is that you cannot
know if the customer finished successfully the
download and then use it as flag to trigger other
functionalities.
I have an alternative code for downloading a file that
allows me to control the download process and even
display it through a progress bar.
But it lacks the capability to allow the customer to
browse his computer and locate a convenient folder
to download the file like the first method.
I am building a web site where some customers, after
having logged in with special privileges, they could
then access a special page where they would be able
to download pdf files.
I would like to give them the capacity to choose
where ( which folder ) to download the pdf file in
their computers.
I wanted to use the following javascript code for
this purpose:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<script language=javascript>
<!--
function GetDownloadPath()
{
var frm = document.forms[0];
var Shell = new ActiveXObject("Shell.Application");
var Folder = new Object;
Folder = Shell.BrowseForFolder
(0, "Choose a download folder", 0);
var FolderItem = new Object;
FolderItem = Folder.Items().Item();
}
-->
</script>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
But someone told me that it only works on IE –and-
additionally, this code only works when it runs from
within a web site whose URL address starts with
“https” instead of “http”. Furthermore, it has to be
listed within “Trusted Sites” in the customer’s
IE Security settings and his computer should enable
ActiveX controls.
So, it seems that this method is a bit tricky and it
would alienate customers who either have different
internet browsers or do not enable ActiveX
controls in their computers.
Another option is to set my application with a
default path “C:\” assuming that every customer
would have this basic drive and add a TextBox
control where the customer could type an
alternative path. But then I would need a method
to verify if the customer typed a correct path.
Please I need the opinion of the experts to
suggest me which one is the best method or
even suggest me a better one.