2

I am trying to read a CSV file from a SharePoint 2013 Document Library. I am using following Powershell command for this.

Import-csv "\\ServerName\sites\SiteName\MyDocumentLibrary\MyCSVFile.csv"

But, I am getting this error The network name cannot be found..

Can somebody let me know, what i am missing ?

1

Try this

$FilePath = "http://ServerName/sites/SiteName/MyDocumentLibrary/MyCSVFile.csv"
$localPath = "C:\temp\test.csv" #Make sure temp folder exists
$wc = New-Object System.Net.Webclient
$wc.DownloadFile($FilePath, $localPath)
$list = Import-Csv $localPath
  • That's a good alternative method. But, does this imply that we can't read a .csv file directly from a document library(without making a local copy of it). – Amit Tyagi Dec 8 '14 at 19:20
  • I think you can do if you have mapped the library using a Network Drive. – Amal Hashim Dec 8 '14 at 19:26
  • I am getting Exception calling "DownloadFile" with "2" argument(s): "The remote server returned an error: (401) Unauthorized." – Amit Tyagi Dec 8 '14 at 20:08
  • Add this before downloadfile $wc.UseDefaultCredentials = $true – Amal Hashim Dec 8 '14 at 20:11
  • 1
    Ok that means either the file should in local path or network path – Amal Hashim Dec 8 '14 at 21:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.