日期:2014-05-20  浏览次数:20805 次

万能的CSDN:一个我个人认为有挑战的难题,高分邀请版主、高人、牛人、大大等围观!
拘于不可言明的理由,现需实现一个目标,简要而言就是:通过.Net调用IE运行Oracle Application Server上的报告(含参数),获得PDF文件,并按运行报表的参数另存为另一个文件。
  本人搜索测试了几天,还是处于困境,So高分邀请版主、高人、牛人、大大等围观!
  目前IE单独运行Oracle Application Server上的报告成功,并成功获得PDF文件,例如:http://192.168.0.1/reports/rwservlet?server=xxx&envid=US&userid=userid/password@dbname&report=RP001.rdf&destype=cache&desformat=PDF&p_vendor_id_from=00010000&p_vendor_id_to=00010000&p_order_date='28-OCT-2009'(下载成功后,IE状态栏显示“已完成”)
  目前难点在于:
1.需判断报告是否运行完毕,即该PDF文件是否生成完毕?
2.怎样将其按报表的参数另存为另一个文件,并保存到本机。
  假设报表参数:p_vendor_id,p_order_date,则另存的文件名为:"PO_" + p_vendor_id + "_" + p_order_date + ".pdf"

  希望各位提供思路,最好有源码。我认为关键在于.net如何对IE进行控制,可是搜索了很多资料,都无法完成需求。

------解决方案--------------------
WebClient下载的时候也会等的,不过你也可以调用它的异步方法,结束的时候会有事件通知已经完成了

WebClient.DownloadFile (
string address,
string fileName
)

------解决方案--------------------
下载可使用ftpwebrequest或webclient
System.Net.WebClient c ;
public Form1()
{
c = new System.Net.WebClient();
c.DownloadProgressChanged += new System.Net.DownloadProgressChangedEventHandler(c_DownloadProgressChanged);
c.DownloadFileCompleted += new AsyncCompletedEventHandler(c_DownloadFileCompleted);
c.Proxy=WebRequest.DefaultWebProxy;
c.Proxy.Credentials = new NetworkCredential("", "", "");
}
void c_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{
MessageBox.Show("ok");
}
private void btnDownload_Click(object sender, EventArgs e)
{
c.DownloadFileAsync(new Uri(""), @"d:"t.pdf");
}

void c_DownloadProgressChanged(object sender, System.Net.DownloadProgressChangedEventArgs e)
{
progressBar1.Value = e.ProgressPercentage;
}
private void btnQuit_Click(object sender, EventArgs e)
{
if (c!=null)
{
c.CancelAsync();
}
Close();
}