This is a migrated thread and some comments may be shown as answers.

File upload.

8 Answers 189 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
SD
Top achievements
Rank 1
SD asked on 15 Jul 2010, 06:43 AM
Hi Guys, 

Is the right code to be used for file uploading in a non-silverlight env ? 
Manager.ActiveBrowser.Find.ByTagIndex<HtmlInputFile>("input", 0).Upload
              (Path.Combine(Globals.PATH_TO_PAGES, @"..\SupportFiles\EmptyTextFile.txt"), 5000);

I getting an IDE error message for both 'Combine' and 'Globals'...
Am I'm missing a ref etc ?

Ta, 
Seth. 

8 Answers, 1 is accepted

Sort by
0
Alexey Shcherbak
Top achievements
Rank 1
answered on 19 Jul 2010, 02:01 PM
Actually that code won't work ( at least - never worked for my projects)

ab.NavigateTo(checkUrl);
 
var fileDialog = new FileUploadDialog(ab, toAbsPath(testImage), DialogButton.OPEN);
mgr.DialogMonitor.AddDialog(fileDialog);
mgr.DialogMonitor.Start();
 
var uploadFileInputFilter = filters.GetFilterByName("UploadFileInput");
ab.Find.ByParam<HtmlInputFile>(uploadFileInputFilter).Click();
This is what I use - FileUploadDialog works fine.
ab is ActiveBrowser object and fileName goes to "testImage". I recommend stuff filename to absolute path, cause "Open Dialog" stores last opened path and can broke test suite if you uploaded any other files manually between tests and using relative file name.
Last 2 rows is my way to find HtmlInputFile control. I prefer to store all filters in Xml file for easy editing it in case of re-design.

If you have any questions about my code - feel free to ask.



0
Missing User
answered on 19 Jul 2010, 07:45 PM
Hi Alexey and SD,

Thanks for the post, both code snippets should work. But I tried Upload() and I was not able to get it working either. I'll log a bug for this, thanks for the post.

Regards,
Nelson Sin
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
SD
Top achievements
Rank 1
answered on 18 Aug 2010, 05:10 AM
Any updates regarding file uploading ?

Ta. 
0
Konstantin Petkov
Telerik team
answered on 18 Aug 2010, 04:14 PM
Hi SD,

Can you please post the errors you get? You mentioned some IDE errors, does that mean the test class doesn't compile in VS? If so do you have an assembly reference to System.IO where the Path class resides?

Kind regards,
Konstantin Petkov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
SD
Top achievements
Rank 1
answered on 19 Aug 2010, 12:39 AM
Hi Kon, 

Pls refer to my previous post regarding SendKeys. Problem is pretty much solved. 

ta. 
0
Limu
Top achievements
Rank 1
answered on 20 Oct 2010, 03:41 PM

Hi Alexey
Thanks for the code. I was using just HtmlInputFile.upload earlier which used to open the upload dialog and close immediately. When I used your code as below, it opens the dialog, types the file name path and closes without clicking OPEN button. Is there anything else I need to do here?

Manager mgr = Manager.Current;

 

 

 

var fileDialog = new FileUploadDialog(ActiveBrowser, "C:\\filename.type", DialogButton.OPEN);

 

mgr.DialogMonitor.AddDialog(fileDialog);

mgr.DialogMonitor.Start();

 

 

HtmlInputFile fileUpload = ActiveBrowser.Find.ByName<HtmlInputFile>("fileinput");

 

fileUpload.Click();

 

 

Thanks
Shwetha

0
Alexey Shcherbak
Top achievements
Rank 1
answered on 21 Oct 2010, 07:37 AM
AFAIK - no, that was working piece of code. Maybe you should check for any changes in FileUploadDialog -  why it wont click on open button. Also check browser settings (security should be relaxed a lot, according to docs) and try to fiddle around ActiveBrowser object you passing - does that actual Manager.ActiveBrowser instance ? Why not mgr.ActiveBrowser ?
0
Limu
Top achievements
Rank 1
answered on 21 Oct 2010, 08:54 PM
hey Alexey
Yes that is mgr.ActiveBrowser. I believe we dont have to explicitly say mgr.ActiveBrowser according to webAii help. Anyway I also tried giving mgr.ActiveBrowser with no luck. I set the security very low but nothing changed.
Also FileUploadDialog must be correct because it is typing the file path I am passing there. But just the button is not clicking. I read one of your earlier posts where telerik had adviced that since upload dialog is windows dialog and not IE dialog, it works differently or something. Also window and dialog handling assembly is not included in the latest framework I believe. I posted another question for that.
thanks
Tags
General Discussions
Asked by
SD
Top achievements
Rank 1
Answers by
Alexey Shcherbak
Top achievements
Rank 1
Missing User
SD
Top achievements
Rank 1
Konstantin Petkov
Telerik team
Limu
Top achievements
Rank 1
Share this question
or