HellaSym
asked on
How to dynamically build a file name to provide the src path to an iframe
In Javascript, I have been trying to provide a filename to the src property of an iframe.
When I hard-code the filename, it works just fine. But when I try to concatenate the path, it doesn't.
Please help.
When I hard-code the filename, it works just fine. But when I try to concatenate the path, it doesn't.
Please help.
filePath = "devhilvs09\\Data\\Forms\\j50gmqeqtlpv.DOC"
filename= "file://" + filePath;
//this works:
document.getElementById('docIFRAME').src = "file://devhilvs09\\Data\\Forms\\j50gmqeqtlpv.DOC";
//this doesn't:
document.getElementById('docIFRAME').src = filename;
ASKER
In the alert, I see the path as follows:
file://devhilvs09\\Data\\F orms\\j50g mqeqtlpv.D OC
Yet, when it goes to the iframe, an error comes up:
Cannot file 'file://\\devhilvs09\\Data \\Forms\\j 50gmqeqtlp v.DOC. Make sure the path or Internet address is correct.
It adds 2 back-slashes on its own...
file://devhilvs09\\Data\\F
Yet, when it goes to the iframe, an error comes up:
Cannot file 'file://\\devhilvs09\\Data
It adds 2 back-slashes on its own...
Thanks for that info. What exactly did you alert? What if you try to just "write" the filename value (i.e. just use innerHTML to put it in some div)? What browser and version of the browser are you using?
bol
bol
Also please let me know if the code you showed isn't really how you are doing this. The code you posted should not add the backslashes.
bol
bol
Also what is the protocol of the URL you are using on the main page? Is it also file: or is it http:? Is it localhost or on an Internet page?
bol
bol
ASKER
I did alert on filename: alert(filename);
Displaying the filename into a text box displayed it correctly.
I am running on IE 6.0, Version:6.0.2900.2180.xpsp _sp2_qfe.0 90206-1239
Here is the code i am running:
// the file name comes back from the server (c#)
byte[] byteArray = null;
byteArray = ((DesktopDocument)doc).Des ktopFileDa ta;
using (BinaryWriter bw = new BinaryWriter(File.Open(tmp File, FileMode.Create)))
{
bw.Write(byteArray);
bw.Close();
}
// remove the leading "\\\\"
string fullPath = Path.GetFullPath(tmpFile). Substring( 2).ToStrin g();
return fullPath;
// returns the filename to the client side (Javascript)
filename = filename.replace(/\\/g,"\\ \\");
filename = "file://" + filename;
document.getElementById('F ileName'). value = filename;
alert(filename);
document.getElementById('d ocIFRAME') .src = filename;
The iframe is part of a web page running on the localhost. So, yes the protocol is http:// on the main page.
Thanks.
Displaying the filename into a text box displayed it correctly.
I am running on IE 6.0, Version:6.0.2900.2180.xpsp
Here is the code i am running:
// the file name comes back from the server (c#)
byte[] byteArray = null;
byteArray = ((DesktopDocument)doc).Des
using (BinaryWriter bw = new BinaryWriter(File.Open(tmp
{
bw.Write(byteArray);
bw.Close();
}
// remove the leading "\\\\"
string fullPath = Path.GetFullPath(tmpFile).
return fullPath;
// returns the filename to the client side (Javascript)
filename = filename.replace(/\\/g,"\\
filename = "file://" + filename;
document.getElementById('F
alert(filename);
document.getElementById('d
The iframe is part of a web page running on the localhost. So, yes the protocol is http:// on the main page.
Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Thanks for the response and info. I need to look over the code more but can you test this on IE7? It was IE7 that I used (and FF) when I tested and I couldn't duplicate it. I am curious if IE7 will work OK for you. That would let us know it is an IE6 issue and then I will try to find IE6 to test and work with.
bol
bol
I just noticed your second post. Glad you got it working. Let me know if you need any more help or have a question about closing this.
Was it the replace line you changed (in the code you just posted) or some other part of your page you changed? If it was the replace then it seems the issue was something not shown in the original question. I am glad you looked at the other parts and found the problem.
bol
Was it the replace line you changed (in the code you just posted) or some other part of your page you changed? If it was the replace then it seems the issue was something not shown in the original question. I am glad you looked at the other parts and found the problem.
bol
ASKER
Yes, I changed the replace line. However the replace line was there to put back double-backslashes in the path, which Javascript replaced with single backslashes when the path came back from the server.
In any case, I am relieved it works now. Thanks again.
In any case, I am relieved it works now. Thanks again.
If you alert filename (or print it somehow) then what do you see? It seems the results should be the same between the 2 lines.
Let me know if you have any questions or need more information.
b0lsc0tt