Not able to read an excel from SharePoint using C#

%3CLINGO-SUB%20id%3D%22lingo-sub-1586269%22%20slang%3D%22en-US%22%3ENot%20able%20to%20read%20an%20excel%20from%20SharePoint%20using%20C%23%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1586269%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSPAN%3EHello%2C%3C%2FSPAN%3E%3C%2FP%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3EWe%20have%20a%20requirement%20to%20read%20excel%20files%20(xlsx%2C%20xls%20and%20csv)%20from%20SharePoint%20into%20the%20memory%20by%20using%20C%23%20code%20and%20perform%20some%20operations.%3C%2FDIV%3E%3CDIV%3ETo%20achieve%20this%20requirement%2C%20we%20have%20used%20%22Microsoft.Office.Interop.Excel%22%20assembly%26nbsp%3Band%20written%20below%20code%20that%20we%20have%20found%20doing%20google.%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CDIV%20class%3D%22mceNonEditable%20lia-copypaste-placeholder%22%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%20class%3D%22mceNonEditable%20lia-copypaste-placeholder%22%3E%26nbsp%3B%3C%2FDIV%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Code.PNG%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F212183iFC007C5041B9D3AE%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20title%3D%22Code.PNG%22%20alt%3D%22Code.PNG%22%20%2F%3E%3C%2FSPAN%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%E2%80%83%3CSPAN%3EHere%2C%20I%20am%20not%20sure%20whether%20this%20code%20is%20working%20or%20not%2C%20because%20after%20executing%20this%20code%2C%20I%20have%20been%20asked%20to%20enter%20user%20name%20and%20password%20into%20the%20new%20window.%20After%20providing%20a%20username%20and%20password%2C%20an%20error%20is%20occurring%26nbsp%3Bin%20user%20name%20and%20password%20screen.%20Please%20see%20below%20screen%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Error.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F212184iBE6DFBB12769CAEB%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20title%3D%22Error.png%22%20alt%3D%22Error.png%22%20%2F%3E%3C%2FSPAN%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%E2%80%83%3C%2FP%3E%3CDIV%3EThere%20are%20two%20questions%20I%20have.%3C%2FDIV%3E%3CDIV%3E1.%20How%20do%20I%20provide%20username%20and%20password%20in%20a%20code%20itself%2C%20so%20that%20this%20will%20not%20prompt%20to%20enter%3F%3C%2FDIV%3E%3CDIV%3E2.%20Why%20is%20this%20type%20of%20error%20coming%20when%20I%20enter%20a%20username%20and%20password%3F%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3EAny%20help%20would%20be%20much%20appreciated.%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3EOR%20any%20one%20also%20suggests%20if%20I%20can%20use%20any%20other%20way%20to%20read%20excel%20files%20directly%20from%20SharePoint.%3C%2FDIV%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FDIV%3E%3C%2FLINGO-BODY%3E
Occasional Contributor

Hello,

 
We have a requirement to read excel files (xlsx, xls and csv) from SharePoint into the memory by using C# code and perform some operations.
To achieve this requirement, we have used "Microsoft.Office.Interop.Excel" assembly and written below code that we have found doing google.
 
 
 
Code.PNG

 

Here, I am not sure whether this code is working or not, because after executing this code, I have been asked to enter user name and password into the new window. After providing a username and password, an error is occurring in user name and password screen. Please see below screen

 

Error.png

 

There are two questions I have.
1. How do I provide username and password in a code itself, so that this will not prompt to enter?
2. Why is this type of error coming when I enter a username and password?
 
Any help would be much appreciated.
 
OR any one also suggests if I can use any other way to read excel files directly from SharePoint.

 

0 Replies