Here is the solution that i finally got and works successfully.. :)
public void BtnDownload_click(object sender, EventArgs e)
{
var currentRow = dgDownloadFile.SelectedItem;
string sFileName = currentRow.ToString();
string sFullPath = "C:/FilesToDownload/" + sFileName;
Service1Client proxy = new Service1Client();
proxy.DownloadFileCompleted += new ventHandler<DownloadFileCompletedEventArgs>(proxy_DownloadFileCompleted);
proxy.DownloadFileAsync(sFullPath);
}
void proxy_DownloadFileCompleted(object sender, DownloadFileCompletedEventArgs e)
{
if (e.Result == 1)
MessageBox.Show("Download successfully.");
if(e.Result == 2)
MessageBox.Show("File already exists.");
}
[WebMethod]
public int DownloadFile(string FullPath)
{
string[] fn = FullPath.Split('/');
FileStream fileStream = null;
BinaryReader reader = null;
fileStream = new FileStream(FullPath, FileMode.Open, FileAccess.Read);
reader = new BinaryReader(fileStream);
byte[] fileeBytes = reader.ReadBytes((int)fileStream.Length);
string DownloadPath = "C:/Documents/" + fn[2];
if (!File.Exists(DownloadPath))
{
FileStream outputStream = new FileStream(DownloadPath, FileMode.Create);
outputStream.Write(fileeBytes, 0, fileeBytes.Length);
outputStream.Close();
return 1;
}
else
{
return 2;
}
}
clientaccesspolicy.xml
<access-policy>
<cross-domain-access>
<policy>
<allow-from http-request-headers="SOAPAction">
<domain uri="https://*" />
</allow-from>
<grant-to>
<resource path="/" include-subpaths="true" />
</grant-to>
</policy>
</cross-domain-access>
</access-policy>
crossdomain.xml
<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<allow-http-request-headers-from domain="*" headers="SOAPAction,Content-Type" />
</cross-domain-policy>