Without seeing the code you're using nobody can offer advice that's more than just a wild guess.
Unable to import data from csv file to existing SharePoint on premise list
I have tried powershell to import data but I keep getting the errors like
You cannot call a method on a null valued expression.
Cannot index into a null array
Can anyone help me in this or suggest any other method to do the import like JavaScript
Windows for business | Windows Server | User experience | PowerShell
4 answers
Sort by: Most helpful
-
-
Anonymous
2020-11-03T03:55:08.547+00:00 Hi,
Please post your current powershell script and the full error message. It helps others understand your problem.
Best Regards
Ian -
Hemanth Reddy S 1 Reputation point
2020-11-03T11:36:01.87+00:00 Hello,
Please find the script below
Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue
$CSVData= Import-CSV -path "mypath"
$web= Get-SPWeb -identity "https://mysite"
$list= $web.Lists["listname"]foreach ($row in $CSVData)
{
$item= $list.Items.Add();
$item["Title"]= $row.Title
$item.Update()}
Error message-
Cannot index into a null array.
$list= $web.Lists["listname"]You cannot call a method on a null-valued expression.
$item= $lists.Item.Add();Cannot index into a null array.
$item["Title"] = $row.TitleYou cannot call a method on a null-valued expression.
$item.Update() -
Anonymous
2020-11-04T04:42:38.19+00:00 Hi,
You see all these error messages because
$web
is null. Please check the result returned byGet-SPWeb
. Also according to the help document, to store the results of Get-SPWeb in a local variable, the Start-SPAssignment and Stop-SPAssignment cmdlets must be used to avoid memory leaks.https://learn.microsoft.com/en-us/powershell/module/sharepoint-server/get-spweb?view=sharepoint-ps
Best Regards,
Ian============================================
If the Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.