Automating file management in SharePoint often requires stepping outside of the browser interface. While modern developers frequently turn to PowerShell or specialized APIs, there are many scenarios where you need a lightweight, command-line solution that works within standard batch scripts or legacy environments. Whether you are restricted from using PowerShell or simply need a quick way to push files to a document library, leveraging WebDAV and native Windows commands is a powerful strategy.
In this guide, you will learn how to use the net use and copy commands to interact with SharePoint libraries as if they were local network shares. This approach is particularly useful for SharePoint 2010, 2013, and 2016 environments, as well as certain SharePoint Online configurations.
Method 1: Mapping a Network Drive with Net Use
The most reliable way to upload files via the command line is to temporarily map your SharePoint document library to a local drive letter. This method allows you to pass specific credentials, making it ideal for automated tasks that run under a different service account.
To map the drive, you use the net use command followed by the URL of your document library. Once the drive is mapped, you can use the standard copy or xcopy commands to move your files.
:: Map the SharePoint library to drive R:
net use r: https://yourcompany.sharepoint.com/documents [password] /user:domainName\username
:: Copy your file to the new drive
copy c:\localfolder\datafile.txt r:\datafile.txt
:: Optionally, disconnect the drive when finished
net use r: /delete
This approach is highly effective because it handles authentication at the session level. You can specify whatever credentials you need, ensuring that the upload process has the correct permissions to write to the library.
Method 2: Using the DavWWWRoot Path
If you prefer not to map a drive letter, you can use the UNC (Universal Naming Convention) path directly. Windows uses a special service called DavWWWRoot to handle WebDAV connections to SharePoint servers. This allows you to treat a URL like a traditional file share path.
If your SharePoint library URL is http://sharepoint/Site/SubSite/Library, the corresponding UNC path would look like this:
copy "C:\temp\report.pdf" "\\sharepoint\DavWWWRoot\Site\SubSite\Library\report.pdf"
Important Note: For the DavWWWRoot method to function correctly, you must have an active File Explorer connection or have recently authenticated to the site. If the connection is cold, the command may return a "Network path not found" error. This method is best suited for quick manual uploads or scripts running in an active user session.
Troubleshooting Common Connection Issues
When working with the command line and SharePoint, you might encounter specific errors related to the WebClient service or authentication. Here are the most common hurdles and how to clear them:
1. The WebClient Service
Both methods described above rely on the Windows WebClient service. If this service is stopped, you will receive errors when trying to connect to a WebDAV path. You can ensure it is running by executing this command in an elevated prompt:
net start webclient
2. File Size Limits
By default, Windows limits WebDAV file transfers to approximately 50MB. If you are trying to upload large datasets via the command line, you may need to adjust the FileSizeLimitInBytes registry key located at:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\WebClient\Parameters.
3. Trusted Sites
Ensure that your SharePoint URL is added to the Trusted Sites zone in your Internet Options. This reduces the number of authentication prompts and allows the net use command to pass credentials more smoothly.
Modern Alternatives: When to Move Beyond Batch
While the command line methods above are excellent for legacy support and simple batch scripts, modern SharePoint environments (especially SharePoint Online/Microsoft 365) have evolved. If you find that WebDAV is inconsistent due to Multi-Factor Authentication (MFA), consider these alternatives:
- CLI for Microsoft 365: A cross-platform command-line interface that allows you to manage SharePoint and Microsoft 365 from any shell (Bash, Cmd, PowerShell).
- PnP PowerShell: Though the original request sought to avoid PowerShell, PnP PowerShell is the industry standard for robust, high-speed file operations in modern SharePoint.
Frequently Asked Questions
Why does my net use command fail with 'System error 86'?
System error 86 usually indicates an invalid password or a credential mismatch. Ensure that you are using the correct domain prefix (e.g., DOMAIN\username) and that the account has "Contribute" permissions on the document library.
Can I use these commands for SharePoint Online with MFA enabled?
Directly passing credentials via net use is difficult with Multi-Factor Authentication (MFA). For SharePoint Online, you usually need to use an "App Password" if your organization allows them, or switch to a modern authentication method like the CLI for Microsoft 365.
Does this work with hidden or private document libraries?
Yes, as long as the account you provide in the command has the necessary permissions to access those libraries. The command line respects the same permission inheritance as the web interface.
Wrapping Up
Uploading files to SharePoint via the command line is a reliable technique for automating routine tasks without the overhead of complex scripts. By utilizing net use to map a drive or the DavWWWRoot path for direct copying, you can integrate SharePoint into your existing workflows seamlessly. Always remember to verify that the WebClient service is active and that your site is trusted to ensure a smooth, error-free experience.