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.