<add key="ProofFileSavePath" value="D:\\Websites\xyz\ABC\Files\" />
private async Task DownloadPdf(string proofFileUrl, long batchFileDetailId, string renderedRawId, bool isNewFileForRenderedRawId, string masterProofFileDownloadDate)
{
var methodName = "DownloadPdf";
if (!string.IsNullOrEmpty(proofFileUrl))
{
if (isNewFileForRenderedRawId)
{
using (var client = new WebClient())
{
var uri = new Uri(proofFileUrl);
client.DownloadFileCompleted += DownloadFileCallback;
var fileInfo = new FileInfo(uri.AbsolutePath);
if (!string.IsNullOrEmpty(fileInfo.Extension))
{
var proofFileName = Path.GetFileName(uri.LocalPath);
client.QueryString.Add(Constants.BatchFileDetailId, batchFileDetailId.ToString());
client.QueryString.Add(Constants.ProofFileName, proofFileName);
client.QueryString.Add(Constants.RenderedRawId, renderedRawId);
var proofFileSaveFullPath = Path.Combine(CommonUtil.ProofFileSavePath, proofFileName);
await client.DownloadFileTaskAsync(uri, proofFileSaveFullPath);
}
}
}
else
{
UpdateIsProofReadyFlag(batchFileDetailId, proofFileUrl, renderedRawId, masterProofFileDownloadDate, false);
}
}
else
{
_loggingHelper.Log(LoggingLevels.Error,
"Class: " + _className + " :: " + methodName + " :: " +
"Proof File Url not found");
}
}
What I have tried:
<add key="ProofFileSaveNetworkPath" value="\\ServerName\ShareName\" />
<add key="ProofFileSaveNetworkUid" value="yourUsername" />
<add key="ProofFileSaveNetworkpwd" value="yourPassword" />
private async Task DownloadPdf(string proofFileUrl, long batchFileDetailId, string renderedRawId, bool isNewFileForRenderedRawId, string masterProofFileDownloadDate)
{
var credentials = new NetworkCredential(CommonUtil.ProofFileSaveNetworkUid, CommonUtil.ProofFileSaveNetworkpwd);
CredentialManager.SaveCredentials("NetworkCredentials", credentials);
var methodName = "DownloadPdf";
if (!string.IsNullOrEmpty(proofFileUrl))
{
if (isNewFileForRenderedRawId)
{
var networkFolder = CommonUtil.ProofFileSaveNetworkPath;
using (var client = new WebClient())
{
var uri = new Uri(proofFileUrl);
client.DownloadFileCompleted += DownloadFileCallback;
var fileInfo = new FileInfo(uri.AbsolutePath);
if (!string.IsNullOrEmpty(fileInfo.Extension))
{
var proofFileName = Path.GetFileName(uri.LocalPath);
client.QueryString.Add(Constants.BatchFileDetailId, batchFileDetailId.ToString());
client.QueryString.Add(Constants.ProofFileName, proofFileName);
client.QueryString.Add(Constants.RenderedRawId, renderedRawId);
var proofFileSaveFullPath = Path.Combine(networkFolder, proofFileName);
if (credentials != null)
{
client.Credentials = new NetworkCredential(credentials.UserName, credentials.Password);
}
await client.DownloadFileTaskAsync(uri, proofFileSaveFullPath);
}
}
}
else
{
UpdateIsProofReadyFlag(batchFileDetailId, proofFileUrl, renderedRawId, masterProofFileDownloadDate, false);
}
}
else
{
_loggingHelper.Log(LoggingLevels.Error,
"Class: " + _className + " :: " + methodName + " :: " +
"Proof File Url not found");
}
}