2014-06-05 55 views
0

我们已被要求去通过网址从我们的客户网站下载订单文件。 我想做这样的事情。从变量URL下载文件c#

string remoteUri = "http://www.contoso.com/library/homepage/images/"; 
string fileName = "ms-banner.gif", myStringWebResource = null; 

// Create a new WebClient instance. 
using (WebClient myWebClient = new WebClient()) 
{ 
    myStringWebResource = remoteUri + fileName; 
    // Download the Web resource and save it into the current filesystem folder. 
    myWebClient.DownloadFile(myStringWebResource, fileName);   
} 

但是,由于我们必须在我们发布的网址中指定日期和时间,因此网址将会变化。

而且我们下载的文件也是可变的。

由于我是C#的新手,我想就如何实现这一点提供建议?

提前致谢

+1

你说URL /文件会根据什么变量?你有一个可能的URL的例子吗?我看不出问题在哪里?您不确定如何构建基于日期和时间的网址? –

回答

0

这取决于如何生成URL。他们是否遵循一种模式?你事先知道他们吗?

private void GetVariableFile(string remoteUri, string filename) { 
string myStringWebResource = null; 

// Create a new WebClient instance. 
using (WebClient myWebClient = new WebClient()) { 
    myStringWebResource = remoteUri + fileName; 
    // Download the Web resource and save it into the current filesystem folder. 
    myWebClient.DownloadFile(myStringWebResource, fileName); 
    //Do stuffs   
    } 
} 

你可能想通过开放的&获得,它将处理需要返回结果的下载和阐述,或在案件的方法文件,改变返回类型,以便它可以返回信息你需要。