0

I am developing an Windows Forms Application in .NET 4.0 on Windows 8 RTM (UAC disabled) with Visual Studio 2012. My current problem is that when i download an file with WebClient and try to access it after finishing download, File.Exists shows false. If i open Windows Explorer the file exists and has more than 10MB. For example it is an video file and if i try to convert it via ffmpeg, ffmpeg shows me that it can not find the file C:\.... but if i copy that path and paste it into explorer, it opens the video. What goes wrong ? "Run as Administrator" does not help. Here is the code.

String video = Path.Combine(Environment.CurrentDirectory, "tempVideo.mp4");
WebClient downloader = new WebClient();
downloader.DownloadFile(new Uri("http://someurl/somevideo.mp4"), video); //download is successfull
FileInfo dlVideo = new FileInfo(video);
if(dlVideo.Exists) //always false, File.Exists(video) also false
{
//Some other actions on file
}
Dante May Code
  • 11,177
  • 9
  • 49
  • 81
Suchiman
  • 1,636
  • 2
  • 20
  • 30

2 Answers2

0

In Windows 7, files downloaded from the web are blocked by default and have to be unblocked in order for them to be accessed via external programs:

Likely it's the same in Windows 8. As for unblocking via code:
Unblock File from within .net 4 c#

Community
  • 1
  • 1
Shadow The GPT Wizard
  • 66,030
  • 26
  • 140
  • 208
0

Finally i found the problem, it was very stupid and embarrassing. The code example was very simplyfied as my whole abstract classes would blow this question. Somewhere in my abstract base class, the extension was added twice, so the output file was tempVideo.mp4.mp4 . Windows Explorer seems to ignore the extension and thereby it was the only program who opened the file.

Suchiman
  • 1,636
  • 2
  • 20
  • 30
  • It's not "ignoring" the extension, it's hiding it by default. Press ALT --> Tools --> Folder Options --> View --> Hide extension for known file types. – Shadow The GPT Wizard Sep 23 '12 at 16:01
  • @ShadowWizard no i mean that explorer opens the tempVideo.mp4.mp4 if i type C:\path\to\tempVideo.mp4 so the extension is ignored at this part – Suchiman Sep 23 '12 at 16:05