0

I am trying to download image files from my web directory ( on IIS ) , so i tried to use web client to download the files by looping them . i got 2 applications , 1 is the web app that i deployed , another is a WPF app where i try to download files from web app . here are my codes:

     public StartWindow()
        {
            InitializeComponent();        
            string fileUploadDirectory = ConfigurationManager.AppSettings.Get("path"); 
          //  string fullpath = System.IO.Path.Combine(fileUploadDirectory, daoWordPuzzle.GetfileURL().Substring(2)); // removes  ( ~/ ) . 
 string fullpath = "http://localhost/iStellarMobile_deploy/Designs/";
                DirectoryInfo d = new DirectoryInfo(fullpath);
                FileInfo[] Files = d.GetFiles("*.png");
                foreach (FileInfo file in Files)
                {
                    string root = file.DirectoryName;
                    DownloadFile(root);
                }
        }

   protected void DownloadFile(string urlAddress)
    {
        client = new WebClient();     
        string currentpath = System.IO.Directory.GetCurrentDirectory() + @"\ImagesTest"; // Save under ImagesTest folder.
        client.DownloadFile(urlAddress, currentpath);    
    }

Images are in the folder of Designs .. which is what i am trying to download... Then in my App.config :

  <appSettings>
<add key="path" value="http://localhost/iStellarMobile_deploy" />

But yet when i run the WPF application , it shows error on this line :

DirectoryInfo d = new DirectoryInfo(fullpath);

Error : URI format not supported.

Previously i was using ( this works for downloading textfile but not multiple textfiles ) :

protected void DownloadData(string strFileUrlToDownload)
    {
        WebClient client = new WebClient();
        byte[] myDataBuffer = client.DownloadData(strFileUrlToDownload);         

        MemoryStream storeStream = new MemoryStream();

        storeStream.SetLength(myDataBuffer.Length);
        storeStream.Write(myDataBuffer, 0 , (int)storeStream.Length);

        storeStream.Flush();

        string currentpath = System.IO.Directory.GetCurrentDirectory() + @"\Folder"; //folder to contain files.

        using (FileStream file = new FileStream(currentpath, FileMode.Create, System.IO.FileAccess.ReadWrite))
        {
            byte[] bytes = new byte[storeStream.Length];
            storeStream.Read(bytes, 0, (int)storeStream.Length);
            file.Write(myDataBuffer, 0, (int)storeStream.Length);
            storeStream.Close();
        }

        //The below Getstring method to get data in raw format and manipulate it as per requirement
        string download = Encoding.ASCII.GetString(myDataBuffer);


    }

My deployed web is on C:/inetpub/wwwroot . So am i doing the wrong thing? i am trying to download multiple files by looping them in directory.

user2376998
  • 1,061
  • 7
  • 32
  • 65
  • You're trying to access files over http while using a handler designed for file systems... – UIlrvnd Sep 11 '13 at 01:32
  • Sorry but i don't understand what u meant – user2376998 Sep 11 '13 at 01:33
  • Not sure i can explain it either, but that just won't work... – UIlrvnd Sep 11 '13 at 01:35
  • Why is that so? because i trying to access a http for its directory? and DirectoyInfo and stuffs only let u access the app files? – user2376998 Sep 11 '13 at 01:36
  • I think Stefan is trying to say that http is different from ftp. – Mark Sep 11 '13 at 01:39
  • i trying to use IO to find the files in that directory that i have input . the directory is a http ... so what can i do to correct it? – user2376998 Sep 11 '13 at 01:40
  • In a nutshell: accessing/browsing your own file system is very different from accessing/browsing a remote one... Use fpt or http requests. – UIlrvnd Sep 11 '13 at 01:44
  • Are the web application and the file reader on the same computer, then why not just use the file path instead of the http url? You could map a path in windows explorer to make it easier, such as i:. If they are on separate servers and you want to use the http url to access the files then you will need to implement this request in your web server or use an ftp server or web file server (such as hfs) and use the appropriate query semantics. – acarlon Sep 11 '13 at 01:49
  • So i have to use httprequest? but its there is no page for the to display the directory.. its just a directory. I need to create a page to show the list of directories? is HTTPrequest capable of getting directories files without creating a page to show directories? – user2376998 Sep 11 '13 at 01:54
  • http://stackoverflow.com/questions/124492/c-sharp-httpwebrequest-command-to-get-directory-listing – UIlrvnd Sep 11 '13 at 01:56
  • yes i was referring to that as well , but that needs a page to show a list of directories , what if i don't have a page to show? can HTTP still access the directories where the files is? – user2376998 Sep 11 '13 at 02:03
  • http://technet.microsoft.com/en-us/library/cc731109(v=WS.10).aspx – UIlrvnd Sep 11 '13 at 02:55
  • i have enabled directory browsing but my DirectoryInfo keep giving me error of Uri not supported – user2376998 Sep 11 '13 at 03:27
  • http://localhost/iStellarMobile_deploy/Designs/ shows a list of directory but i still can't download it ... saying Uri not supported – user2376998 Sep 11 '13 at 03:32
  • Request the file with webclient like in your second example. – UIlrvnd Sep 11 '13 at 12:34

0 Answers0