C#访问共享文件夹问题

来源:百度知道 编辑:UC知道 时间:2024/05/22 06:14:43
我想访问一个共享文件夹,于是我就直接写了一条代码

System.Diagnostics.Process.Start(@"\\192.168.0.2\文件夹");

我想判断是否成功连接共享文件夹,应该怎么写?

调用windows的API吧

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace WindowsApplication1
{
#region Windows API enum and struct
public enum ERROR_ID
{
ERROR_SUCCESS = 0, // Success
ERROR_MORE_DATA = 234,
ERROR_NO_BROWSER_SERVERS_FOUND = 6118,
ERROR_INVALID_LEVEL = 124,
ERROR_ACCESS_DENIED = 5,
ERROR_INVALID_PARAMETER = 87,
ERROR_NOT_ENOUGH_MEMORY = 8,
ERROR_NETWORK_BUSY = 54,
ERROR_BAD_NETPATH = 53,
ERROR_NO_NETWORK = 1222,
ERROR_INVALID_HANDLE_STATE = 1609,
ERROR_EXTENDED_ERROR = 1208
}

public enum RESOURCE_SCOPE
{
RESOURCE_CONNECTED = 1,
RESOURCE_GLOBALNET = 2,
RESOURCE_REMEMBERED = 3,
RESOURCE_RECENT = 4,