class Program { static void Main(string[] args) { // give the excel file path. string filePath = "exel file path"; DownloadXLFile(filePath, "my path"); } public static void DownloadXLFile(string strPath, string strDest) { try { ExcelService xlService = new ExcelService(); xlService.Url = "http://mysiteurl/_vti_bin/ExcelService.asmx"; System.Net.CredentialCache.DefaultNetworkCredentials.UserName = "username"; System.Net.CredentialCache.DefaultNetworkCredentials.Password = "password"; System.Net.CredentialCache.DefaultNetworkCredentials.Domain = "http://siteurl/path"; //xlService.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials; Status[] status; string sessionId = xlService.OpenWorkbook(strPath, String.Empty, String.Empty, out status); // Here iam getting exception byte[] workbook = xlService.GetWorkbook(sessionId, WorkbookType.FullWorkbook, out status); FileStream fs = new FileStream(strDest, FileMode.Create); fs.Write(workbook, 0, workbook.Length); fs.Dispose(); } catch (Exception ex) { throw new Exception("CreateFile - " + ex.Message); } } }
xlService.Credentials = new NetworkCredential(username,password); e.g:- xlService.Credentials = new NetworkCredential("myName","myPassword");
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)