当前位置:网站首页>C # upload pictures to shared folder
C # upload pictures to shared folder
2022-07-22 16:25:00 【Cherry Blossom】
C# Upload pictures to shared folder
Use net dos command
- Try connecting to a shared folder
bool status = connectState(@"\\IP\uploadImages", " User login ", " The login password ");
/// <summary> /// Connect shared files /// </summary> /// <param name="path"> Shared file address </param> /// <param name="userName"> user name </param> /// <param name="passWord"> password </param> /// <returns>true: Successful connection false: The connection fails </returns> public static bool connectState(string path, string userName, string passWord) { bool Flag = false; Process proc = new Process(); try { proc.StartInfo.FileName = "cmd.exe"; proc.StartInfo.UseShellExecute = false; proc.StartInfo.RedirectStandardInput = true; proc.StartInfo.RedirectStandardOutput = true; proc.StartInfo.RedirectStandardError = true; proc.StartInfo.CreateNoWindow = true; proc.Start(); string dosLine = "net use " + path + " " + passWord + " /user:" + userName; proc.StandardInput.WriteLine(dosLine); proc.StandardInput.WriteLine("exit"); while (!proc.HasExited) { proc.WaitForExit(1000); } string errormsg = proc.StandardError.ReadToEnd(); proc.StandardError.Close(); if (string.IsNullOrEmpty(errormsg)) { Flag = true; } else { throw new Exception(errormsg); } } catch (Exception ex) { throw ex; } finally { proc.Close(); proc.Dispose(); } return Flag; }
/// <summary> /// Select pictures or files to upload to the server nfs Shared folders /// </summary> public void DosCopyImage() { if (status == false) { GLOBALS.msgbox(" Continuous server failure !"); return; } string id = DateTime.Now.ToString("yyyyMMddHHmmss"); string isPath = DateTime.Now.ToString("yyyy-MM-dd"); string Path = IISPATH + isPath; if (!Directory.Exists(IISPATH)) { Directory.CreateDirectory(IISPATH); } string txtFilePath = ""; OpenFileDialog openFileDialogTemp = new OpenFileDialog(); openFileDialogTemp.Title = " Select the picture to upload "; openFileDialogTemp.Filter = "*.jpg,*.png,|*.jpg;*.png;";// If you need to upload a file, add it DialogResult dr = openFileDialogTemp.ShowDialog(); if (!File.Exists(openFileDialogTemp.FileName)) { GLOBALS.msgbox(" Photo is empty , Please choose a picture "); return; } if (dr == DialogResult.OK) { txtFilePath = openFileDialogTemp.FileName; } if (txtFilePath.Trim() == "") { GLOBALS.msgbox(" Please select a file !"); return; } string filePath = this.txtFilePath.Text; string uploadUrl = IISPATH + isPath + "/" + id + ".jpg"; try { File.Copy(filePath, uploadUrl);// Copy all the files in the folder 、 Directory to the specified folder GLOBALS.msgbox(" Upload successful !"); } catch (Exception) { } }
Before using this method , To open the first cmd window , use dos Whether the command runs normally
command : Open the connection :net use \\IP Address \uploadImages$ password /user: user name Be careful : There are only three spaces
Delete connection :net use \\IP Address \uploadImages$ password /user: user name \del
net use Error resolution :
Error number 5, Access denied : It's very likely that the user you are using is not with administrator rights , First of all, raise the authority ;
Error number 51,Windows Unable to find network path : There's something wrong with the network ;
Error number 53, No network path found :ip Wrong address ; Target is not powered on ; The goal is lanmanserver Service not started ; The target has a firewall ( Port filtering );
Error number 67, No network name found : Yours lanmanworkstation The service is not started or the target is deleted uploadImages$;
Error number 1219, The supplied credentials conflict with an existing set of credentials : You've established a... With each other uploadImages$, Please delete and connect ;
Error number 1326, Unknown user name or wrong password : The reason is obvious ;
边栏推荐
- Mnemonic search
- "Demand optimization" uses PostMessage to solve the cross domain problem of localstorage
- EasyCVR平台V2.5.0版本及以上如何配置WebRTC协议实现低延迟播放?
- The big problem of HA automatic failover (active) namenode
- 计算机网络之DNS面试题
- 字符编码问题
- Docker data management case - MySQL data persistence
- Discrete problem sorting
- 计算机网络之应用层面试题
- The appearance sequence of question 38 in C language. Three methods (traversal method, recursive method and wolf killing method)
猜你喜欢
2022 those "hidden rules" in the interview of testers, don't step on the pit
『需求优化』使用 postMessage 解决 localStorage 跨域问题
ENVI_ Idl: batch production of thematic maps
How far can TTL, RS232 and 485 transmit?
Session共享问题
嵌入式IDE原理 OpenOCD介绍 以及stlink如何连接stm32板子
Evening Sky
这个好用的办公网优化工具,官宣免费了
DOM style operation
C#服务器NFS共享文件夹搭建与上传图片文件
随机推荐
12 nodes of DOM
计算机网络之DNS面试题
[elaborate] ES6 import, export and other operations
Remember a composer dependency problem requires composer runtime API ^2.0.0 - > no matching package found
Segment tree learning record
[SSM]SSM整合③(接口测试)
TTL、RS232、485到底能传输多远距离?
Learning notes of line segment tree
MP查询条件
正畸学经典书籍
Mock simulates data and initiates get and post requests (nanny level tutorials are sure to succeed)
The LAAS solution of elephant swap has risen rapidly and built a new defi2.0 protocol
Rquestmapping's annotation function, annotation usage range, and attribute details of annotations
A 15-year-old ABAP veteran's suggestion: understanding these basic knowledge is beneficial to ABAP development
关于引体向上器和腰垫的选购说明
C#服务器NFS共享文件夹搭建与上传图片文件
傍晚的天空
万亿市值公链竞争白热化,新公链还有机会吗?
服务器与本地资料互传的命令行代码
JVM内存模型:虚拟机栈