Issue
I have some problem. I download a file after clicking an icon on web application. My next step is executed before the record file was downloaded. I want to wait until file is downloaded?
Does anyone know how to wait for that?
Solution
I use the following script (filename should be passed in).
The first part waits till the file appears on disk (fine for chrome)
The second part waits till it stops changing (and starts to have some content)
var downloadsPath = Environment.GetEnvironmentVariable("USERPROFILE") + @"\Downloads\" + fileName;
for (var i = 0; i < 30; i++)
{
if (File.Exists(downloadsPath)) { break; }
Thread.Sleep(1000);
}
var length = new FileInfo(downloadsPath).Length;
for (var i = 0; i < 30; i++)
{
Thread.Sleep(1000);
var newLength = new FileInfo(downloadsPath).Length;
if (newLength == length && length != 0) { break; }
length = newLength;
}
Answered By - Dmitry
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.