/    Sign up×
Community /Pin to ProfileBookmark

Save the file but not the webpage with the filename

function winopen(proj,rep,filename)
{
win3=window.open();
win3.document.write(filename);
win3.document.execCommand(‘saveAs’,1,filename);
}

Currently the function can only save the webpage with the filename printed on it. However, I hope to save the file instead of just a filename. The variables that i pass to the function contain:

1) proj –> contain project location
2) rep –> contain report location
3) filename –> contain filename of a specific file.eg: test.xls

Moreover, can the file be saved at the exact location specified by project+report location?eg: C://project/report , instead of the starting at Desktop in the save dialog box.

Experts, please help me!! Thank you in advance!

to post a comment
JavaScript

22 Comments(s)

Copy linkTweet thisAlerts:
@PittimannMar 03.2005 — Hi!

Can you please point out, if you want to open C:projectreporttest.xls and have the dialogue pop up or if you want to write something to an empty file and have the dialogue pop up with the specified location and file name?

It isn't really clear to me, what you want to appear in the new window.

Cheers - Pit
Copy linkTweet thisAlerts:
@Huang_YouyiauthorMar 03.2005 — Thanks for replying!

I need to save a file (referenced by filename) to a specific folder in my computer. The location of the folder will be proj+rep because proj=S://project1 and rep=/report1.

Initially I was working a upload process with <input type=file...>. However, due to server restrictions, I had to try to save the file to the folder via execCommand('saveAs'...)

You may ask why I do not want to copy the file from my computer desktop and paste it into the folder. It is because I am trying to do it on a webpage to allow user to select file and then save into a common directory in my company.

Hope you can understand what I am trying to say, because I am really new to programming. Need alot of experts' helps!
Copy linkTweet thisAlerts:
@PittimannMar 03.2005 — Hi![i]Originally posted by Huang Youyi [/i]

[B]It is because I am trying to do it on a webpage to allow user to select file and then save into a common directory in my company.[/B][/QUOTE]
Do these 'users' have access to a local network in your company? Otherwise, if the website is online somewhere, how should the user's machine be able to save something to your local harddisk?

Cheers - Pit
Copy linkTweet thisAlerts:
@Huang_YouyiauthorMar 03.2005 — Hi Pit,

Ask you a question:

If the user can create folder in the specific drive, does he has the access to the drive? If yes, then I guess he has the access to local network.
Copy linkTweet thisAlerts:
@PittimannMar 03.2005 — Hi!

So the users are company members?

Cheers - Pit
Copy linkTweet thisAlerts:
@Huang_YouyiauthorMar 03.2005 — Yes, the users are my company members. But, only members from my own department can access to the drive. Do you think you can help me? I really need some guidances and source codes to help me through.
Copy linkTweet thisAlerts:
@PittimannMar 03.2005 — Hi!

You said 'The location of the folder will be proj+rep because proj=S://project1 and rep=/report1.'.

That should be the destination. Any script to copy the file from a users local harddrive to the network drive ('yours') would need the source location as well.

Due to the fact, that your code would only work in IE, I assume, that all people who will deal with the script use IE on their local machines. If so it might be more elegant to let the users browse to their file with a file input (like the one you are dealing with in your other thread) and let ActiveX do the copy business.

Cheers - Pit
Copy linkTweet thisAlerts:
@PittimannMar 03.2005 — Hi!

Just incase the usage of ActiveX would be ok in your company, this will get you started:&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt;
&lt;title&gt;Example&lt;/title&gt;
&lt;SCRIPT LANGUAGE="JavaScript"&gt;
&lt;!--
var errM;
var fso;
var fInp;
function copyF(proj,rep){
var success=0;
fInp=document.myform.file1.value;
var nName=document.myform.newName;
if(fInp==''){
alert('You didn\'t select a file to be copied!');
return false;
}
fso = new ActiveXObject("Scripting.FileSystemObject");
fileObj = fso.GetFile(fInp);
if(fileObj.Size&gt;0){
fName=fileObj.Name;
newF=proj+rep+fName;
f1=fso.FileExists(newF);
f2=fso.FileExists(proj+rep+nName.value);
msg1='A file with the name "';
msg2='" already existsnin the destination folder "'+proj+rep+'"!nPlease enter a different name into the textfield.';
if(f1&amp;&amp;(nName.value==''||nName.value==fName)){
alert(msg1+fName+msg2);
nName.style.display='';
nName.focus();
return false;
}
else if(f2){
alert(msg1+nName.value+msg2);
nName.style.display='';
nName.focus();
return false;
}
else{
fileObj.Copy(newF);
success=1;
}
if(!f2&amp;&amp;nName.value!=''&amp;&amp;nName.value!=fName){
newF=proj+rep+nName.value;
fileObj.Copy(newF)
success=1;
}
}
if(success==1){
nName.style.display='none';
nName.value='';
alert('File "'+fInp+'" successfully copied to "'+newF+'".')
}
}
onerror=function(errnum){
msg='Error:n';
if(!fso.FileExists(fInp)){
msg='Error concerning file "'+fInp+'":n';
}
alert(msg+errnum);
return true
}
--&gt;
&lt;/SCRIPT&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;form name="myform" action="#"&gt;
&lt;input type="file" name="file1" size="50"&gt;&lt;br&gt;
&lt;input name="newName" style="display:none"&gt;&lt;br&gt;
&lt;input type="button" value="copy file to network drive" onclick="copyF('S:\project1\','report\',this.form.newName.value)"&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
Cheers - Pit
Copy linkTweet thisAlerts:
@Huang_YouyiauthorMar 03.2005 — Hi, Pit!

Whether or not my company allow me to use ActiveX, I would like to say a big thank you to you! Thank you, Pit! You have been a great help!!

Kind regards,

youyi
Copy linkTweet thisAlerts:
@PittimannMar 03.2005 — Hi youyi!

You are welcome! I'm glad I could help. ?

Good night and maybe see you soon.

Regards - Pit
Copy linkTweet thisAlerts:
@Huang_YouyiauthorMar 04.2005 — Hi Pit,

If you see this message, I just want to let you know that an error occurred when i input the script you gave me into my company computer.

The error states that: "Automation server can't create object."

Maybe it is the server problem again.

Anyway, I am actually using Lotus Notes Client version 6.0.3 to update and create my company's website. What I can do right now is only to create a button.

By choosing the onclick event handler for the button, i can then input Javascripts into it to make the button more dynamic.

To write HTML codes, what I did was:

1) open a window: win1=window.open();

2) writing HTML codes to win1: win1.document.write("....");

Hence, I feel that it is troublesome to write the HTML scripts. But, I tried to input all the script that you posted to me, and that error message occurred.

If you have any idea what may be going on, please tell me.

Thanks thanks!

Regards,

youyi
Copy linkTweet thisAlerts:
@PittimannMar 04.2005 — Hi!

ActiveX can be very harmful. At least, Microsoft implemented settings in Internet Explorer to let the user chose how it should be handled.

My script 'only' copies something from x to y; it could as well do much harm to your data. Just for testing, you could set the settings for ActiveX (in internet options -> security etc.) to a lower level; you should also know that the settings for 'real' internet and local machine/intranet are different. Play with the settings to find out, at which time the script will run and once knowing that, you and your company can decide whether the risk to have these settings on the machines in question is acceptable or not.

If the decision will be against ActiveX, please let me know.

Good luck! Pit
Copy linkTweet thisAlerts:
@Huang_YouyiauthorMar 04.2005 — Hi Pit!

I managed to save the file into the folder when I enable all the ActiveX requirements in internet security settings.

My folder structure consist of project. Inside the project, there a few types of report folders. Right now, I am only able to save to the project folder, but not to the destinated report folder. Get it so far? ?

Last thing to ask you is that:

1) Is that a error in the coding that you gave me on the last part of HTML codes : <input name="newName" style="display:none">

2) Should it be <input type="text" size="20" name="newName"


style="display:none">?

Regards,

youyi
Copy linkTweet thisAlerts:
@PittimannMar 04.2005 — Hi!

Concerning the folder structure: it will be easy to give you as much flexibility as you need (like getting a list of all subfolders in 'project' and - example: create a select tag to chose one of these subfolders). Would that be useful?

Concerning the '<input name="newName" style="display:none">':

This is no error. The default type of an <input> is 'text', so it can be left out. And as far as the size is concerned - every browser assigns a certain default size to a text input. I didn't care about a specific size, so I could also leave that out. Of course, if you need more or less space, you can use size="whateverSizeYouNeedGoesHere".

Cheers - Pit
Copy linkTweet thisAlerts:
@Huang_YouyiauthorMar 04.2005 — Hi

So you are saying the <input name...> is actually a textfield for user to enter a new filename?

I have a select tag with options for different projects with value eg: S:/project1/ .I also have select tag with options for different reports with value eg: report1/ .Right now, the file just save in project1 folder but not into report1 folder.

There is also an error stating

(Error:'style' is null or not an object)

Almost reaching my goal.. ?

youyi
Copy linkTweet thisAlerts:
@PittimannMar 04.2005 — Hi!So you are saying the <input name...> is actually a textfield for user to enter a new filename?[/QUOTE]This textfield only shows up, if the file selected in the <input type="file"> already exists in the destination folder. I put that into the script to avoid overwriting files. So if a file with the name of the one selected by the user already exists, the user can type a different name into the text field and the selected file will not be saved with the original name, but with the name specified in the text field.

Hard to say, from where you get the "Error:'style' is null or not an object"; I guess you made some little modification somewhere.

If you like, post the code you are currently using (including your selects) for debugging.

Cheers - Pit
Copy linkTweet thisAlerts:
@Huang_YouyiauthorMar 04.2005 — Hi Pit,

You are right, I made some modification to suit my Lotus Notes. I will post it here.

[SIZE=1]6

// Prompt for username and password

var id=prompt("Please enter your Username below:","");

var pw=prompt("Please enter your Password below:","");

checkpassword(id,pw);



// Check username and password

function checkpassword(id,pw)

{

if(id.toLowerCase() =="ng ui yi" && pw==12345678)

openWin(id);

else if(id.toLowerCase() =="sim wee lim" && pw==90670129)

openWin(id);

else

alert('You have entered incorrect Username or Password! Please try again!');

}



// Opening upload window

function openWin(id)

{

win1=window.open("","","height=500,"+

"width=800,resizable,menubar,taskbar,toolbar,scrollbars,location,status");

with(win1.document)

{

var str = "";

str += "<html><head><script language='JavaScript' type='text/javascript'>";



str += "var errM;";
str += "var fso;";
str += "var fInp;";
str += "function copyF(proj,rep,filename,dispname){";
str += "var success=0;";
str += "fInp=filename;";
str += "var nName=dispname;";
str += "alert(proj+rep+filename);";
str += "if(fInp==''){";
str += "alert('You did not select a file to be copied!');";
str += "return false;";
str += "}";

str += "fso = new ActiveXObject('Scripting.FileSystemObject');";
str += "fileObj = fso.GetFile(fInp);";
str += "if(fileObj.Size>0){";
str += "fName=fileObj.Name;";
str += "newF=proj+rep+fName;";
str += "f1=fso.FileExists(newF);";
str += "f2=fso.FileExists(proj+rep+nName.value);";
str += "msg1='A file with the name ';";
str += "msg2=' already exists in the destination folder "+proj+rep+" !Please enter a different name into the textfield.';";
str += "if(f1&&(nName.value=='' || nName.value==fName)){";
str += "alert(msg1+fName+msg2);";
str += "nName.style.display='';";
str += "nName.focus();";
str += "return false;";
str += "}";
str += "else if(f2){";
str += "alert(msg1+nName.value+msg2);";
str += "nName.style.display='';";
str += "nName.focus();";
str += "return false;";
str += "}";
str += "else{";
str += "fileObj.Copy(newF);";
str += "success=1;";
str += "}";
str += "if(!f2&&nName.value!=''&&nName.value!=fName){";
str += "newF=proj+rep+nName.value;";
str += "fileObj.Copy(newF);";
str += "success=1;";
str += "}";
str += "}";
str += "if(success==1){";
str += "nName.style.display='none';";
str += "nName.value='';";
str += "alert('File "+fInp+" successfully copied to "+newF+".')}";
str += "}";
str += "onerror=function(errnum){";
str += "msg='Error:';";
str += "if(!fso.FileExists(fInp)){";
str += "msg='Error concerning the file "+fInp+":';";
str += "}";
str += "alert(msg+errnum);";
str += "return true;";
str += "}";

str += "</script></head>";
str += "<body bgcolor='#cae1ff' text='#3d59ab'>";
str += "<center><h1>Welcome, "+id.toUpperCase()+"!</h1></center>";

// Select upload destination
str += "<center><u><h2>Select upload destination...</h2></u></center>";
str += "<center><h4><table border='2' cellpadding='1' cell spacing='1' width='65%'><tr><td>"+
"<center><form name='project'><u><h3>Select the type of project:</h3></u><select name='projectlist'><option value='#'>"+
"Select an option below...</option><optgroup label='CRT projects'>"+ // Select project
"<option value='S:/QE/Common/QEWeb/Project/CRT_Project/A02'>A02</option>"+
"<option value='S:/QE/Common/QEWeb/Project/CRT_Project/EMG2K3'>EMG2K3</option>"+
"<option value='S:/QE/Common/QEWeb/Project/CRT_Project/EMG2K4'>EMG2K4</option>"+
"<option value='S:/QE/Common/QEWeb/Project/CRT_Project/EMG_PP2'>EMG PP2</option>"+
"<option value='S:/QE/Common/QEWeb/Project/CRT_Project/Esplanade_Salsa'>Esplanade Salsa</option>"+
"<option value='S:/QE/Common/QEWeb/Project/CRT_Project/ITV'>ITV</option>"+
"<option value='S:/QE/Common/QEWeb/Project/CRT_Project/L04'>L04</option>"+
"<option value='S:/QE/Common/QEWeb/Project/CRT_Project/L05ATSC'>L05ATSC</option>"+
"<option value='S:/QE/Common/QEWeb/Project/CRT_Project/L05HD'>L05HD</option>"+
"<option value='S:/QE/Common/QEWeb/Project/CRT_Project/PTV'>PTV</option></optgroup>"+
"<optgroup label='LCD projects'></optgroup><select></form></center>"+
"<td><center><form name='report'><u><h3>Select the type of report or certificate:</h3></u><select name='reportlist'>"+
"<option value='#'>Select an option below...</option>"+ // Select report
"<option value='/CB-Cert_CB-Report'>CB certificate & report</option>"+
"<option value='/EMC_FCC_Report'>EMC_FCC report </option>"+
"<option value='/DFU'>DFU</option>"+
"<option value='/Country_Certificate'>Country certificates</option>"+
"<option value='/Circuit_Diagram'>Circuit diagrams</option></select></form></center>"+
"</td></tr></table></h4></center>";

// Searching
str += "<input type=button onclick='window.location=document.project.projectlist.options"+
"[document.project.projectlist.selectedIndex].value+document.report.reportlist.options"+
"[document.report.reportlist.selectedIndex].value' value='Searching...'>";

// // Select the upload file
str += "<center><u><h2>Select the file for uploading...</h2></u>";
str += "<form name='upload' id='upload' action='#' method='post' enctype='multipart/form-data'>"+
"<input type='file' id='upfile' name='upfile' size='40'><br>";
str += "<input type='text' size='20' name='newName' style='display:none'><br>";
str += "<input type='button' value='Copy file to network drive' "+
"onclick='javacript:copyF(document.project.projectlist.options[document.project.projectlist.selectedIndex].value,"+
"document.report.reportlist.options[document.report.reportlist.selectedIndex].value,"+
"document.upload.upfile.value,document.upload.newName)'></form></center></body></html>";

writeln(str);
}

}

[/SIZE]

Thanks for all the help, Pit!

Regards,

youyi
Copy linkTweet thisAlerts:
@PittimannMar 04.2005 — Hi youyi!

I found 3 lines where you used double quotes where single ones are needed. These are the corrections:

str += "msg2=' already exists in the destination folder '+proj+rep+' !Please enter a different name into the textfield.';";

str += "alert('File '+fInp+' successfully copied to '+newF+'.')}";

str += "msg='Error concerning the file '+fInp+':';";

The problem, that you 'land' in the wrong folder can easily be fixed.

Check out the options of your second select (below one sample line):

"<option value='/EMC_FCC_Report'>EMC_FCC report </option>"+

they all need another slash in the value:

value='/EMC_FCC_Report[COLOR=red]/[/COLOR]'

Maybe there are other little mistakes because of the 'writeln' stuff. I just ran a few tests after having made the modifications I suggested above and they all worked.

Cheers - Pit
Copy linkTweet thisAlerts:
@Huang_YouyiauthorMar 04.2005 — Hi, Pit!

Thanks for running through my scripts! I will work on those mistakes when I get back to office on Monday. Once everything works, I will let you know. Thank you so much!

Relax and enjoy the coming weekend!

Regards,

youyi?
Copy linkTweet thisAlerts:
@PittimannMar 04.2005 — Hi![i]Originally posted by Huang Youyi [/i]

[B]Relax and enjoy the coming weekend![/B][/QUOTE]
Thanks!!

I wish you the same. ?

See you - Pit
Copy linkTweet thisAlerts:
@Huang_YouyiauthorMar 08.2005 — Hi Pit,

I am back ? Yesterday, I wasn't at work. I tried your corrections this morning and found out that the file has sucessfully copied into the folder. However, another similar file named 'undefined',with save type 'FILE',exists everytime I copy a file. Hence, it stopped further copying of file and it detect the same 'undefined' file.

There was another alert message" Error:'style' is null or not an object" .Wondered what did I do wrong. But it looks almost done ?

Sorry to trouble you again!

Kind regards,

youyi
Copy linkTweet thisAlerts:
@Huang_YouyiauthorMar 08.2005 — Hi Pit,

Everything is ok now. Thanks for all your help!

Wish you all the best!

If you see any of my thread again, do not forget to give a few comments. ?

Looking forward to next interaction!

Take care,

youyi
×

Success!

Help @Huang_Youyi spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...