Is there any possible way to upload a file through a gadget I am creating a gadget that takes a word document or .txt file as input, post that to our servers and then we display information to you every day based on that information through the gadget. (the user gets a infoId that will give them their own customized info)
Any ideas would be appreciated.
Thanks.
Thor.

File upload with Sidebar Gadget
jschroeder
var adTypeBinary = 1;
var cfItem = System.Shell.chooseFile(true, "Word Files:*.doc:Text Files:*.txt::", "", "");
if (cfItem.path != "")
{
oStream.Type = adTypeBinary;
oStream.Open;
oStream.LoadFromFile(cfItem.path);
content = oStream.Read;
//upload content
oStream.Close;
oStream = null;
adb123
You won't be able to manipulate the binary stream within JavaScript, all you can do with it is send it via an XMLHttpRequest() Send.
A simple way to check if it's read in okay, is to look at oStream.Size.
Here's the sample code I just tried, which works.
<html>
<head>
<script language="javascript" type="text/javascript">
var adTypeBinary = 1;
var adTypeText = 2;
function init() {
var oStream = new ActiveXObject("ADODB.Stream");
oStream.Type = adTypeText;
oStream.CharSet = "UTF-8";
oStream.Open;
oStream.LoadFromFile(System.Gadget.path + "\\readme.txt");
var z = oStream.ReadText;
content.innerText = z;
oStream.Close;
oStream = null;
}
</script>
</head>
<body onload="init()" style="margin:0px; width:100; height:100">
<div id="content"></div>
</body>
</html>
Karin P
Works fine now! I thought that LoadFromFile method returned a boolean - maybe I was reading the VBScript specs The mistake I was making was that I was outputting status of that boolean on the gadget screen with Document.write - and now I have discovered that document.write cleans out the entire screen before writing out stuff. (that's why I never saw the output from the doc) Didn't see that coming! (I think that's a different behaviour from IE browser - i.e. with document.write cleaning the entire content of the html)
Thanks so much for your help. Really appreciate it.
Thor.
fafnir
Yes, I'm running this inside the Gadget. I'm getting a different error when running in IE browser (Automation server... something pops up). But in the gadget it always give me false on that LoadFromFile method I'm calling. I tried using FSO, but the problem there is that it can't read binary files, only text files. (I tried reading .txt file, and that works fine with FSO, but I need this with binary)
Can you imagine what is going on with that Adodb.Stream object / loadFromFile method
I copied that cope snippet from the post on this thread and it didn't work. Have you tested this in your gadget.
My Vista is RC1 Build 5600.
Thanks for your help!
Thor.
WalidM
When you say "LoadFromFile gives me false", what do you mean - it doesn't return a value.
Srdjan
I am using PHP language for the server script.
poita
Leroy Pierce
Alright. I tried this code snippet - the LoadFromFile method is always returning false on me (no matter what file I pick). Does this work for you (I'm running this as a client javascript code)
Thanks,
Thor.
CharlieRussell
somersault
This is really odd. I just copied and pasted that exact example into my gadget. (I'm using this in my flyout). The LoadFromFile gives me FALSE again... I made a readme file (it's not read-only or anything) and stuck it into my gadget's dir, and even verified it by writing out the path string... (if the file is not found, it seems to throw an exception, but if its found it will either return true or false) I guess my computer/gadget doesn't like Adodb.Stream
Can you think of anything
Thanks!
Thor.
jsale_endeavor
Unfortunately, for security reasons, it's virtually impossible to manipulate the local filesystem using JavaScript. The other way to do this is to have a hidden iframe to do the uploading/posting - but something tells me that the gadget is going to throw that post into a new IE browser instance (which drives me insane :)
Can you think of any workaround
Thanks!
Thor.