1219 Occurs

patrick

Well-known member
Joined
Dec 5, 2021
Messages
256
Programming Experience
1-3
Hello

I'm trying to copy a file from a shared folder.

1219 Occurs


C#:
using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Net;

    public class NetworkConnection : IDisposable
    {
        readonly string _networkName;

        public NetworkConnection(string networkName, NetworkCredential credentials)
        {
            _networkName = networkName;

            var netResource = new NetResource
            {
                Scope = ResourceScope.GlobalNetwork,
                ResourceType = ResourceType.Disk,
                DisplayType = ResourceDisplaytype.Share,
                RemoteName = networkName
            };

            var userName = string.IsNullOrEmpty(credentials.Domain)
                ? credentials.UserName
                : string.Format(@"{0}\{1}", credentials.Domain, credentials.UserName);

            var result = WNetAddConnection2(
                netResource,
                credentials.Password,
                userName,
                0);

            if (result != 0)
            {
                throw new Win32Exception(result, "Error connecting to remote share");
            }
        }

        ~NetworkConnection()
        {
            Dispose(false);
        }

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        protected virtual void Dispose(bool disposing)
        {
            WNetCancelConnection2(_networkName, 0, true);
        }

        [DllImport("mpr.dll")]
        private static extern int WNetAddConnection2(NetResource netResource,
            string password, string username, int flags);

        [DllImport("mpr.dll")]
        private static extern int WNetCancelConnection2(string name, int flags,
            bool force);

        [StructLayout(LayoutKind.Sequential)]
        public class NetResource
        {
            public ResourceScope Scope;
            public ResourceType ResourceType;
            public ResourceDisplaytype DisplayType;
            public int Usage;
            public string LocalName;
            public string RemoteName;
            public string Comment;
            public string Provider;
        }

        public enum ResourceScope : int
        {
            Connected = 1,
            GlobalNetwork,
            Remembered,
            Recent,
            Context
        };

        public enum ResourceType : int
        {
            Any = 0,
            Disk = 1,
            Print = 2,
            Reserved = 8,
        }

        public enum ResourceDisplaytype : int
        {
            Generic = 0x0,
            Domain = 0x01,
            Server = 0x02,
            Share = 0x03,
            File = 0x04,
            Group = 0x05,
            Network = 0x06,
            Root = 0x07,
            Shareadmin = 0x08,
            Directory = 0x09,
            Tree = 0x0a,
            Ndscontainer = 0x0b
        }
    }




var networkPath = @"//10.20.41.21/sharefolder"; <======= Did I enter this part incorrectly?

var networkPath = @"\\10.20.41.21\sharefolder"; <======= Did I enter this part incorrectly?

var networkPath = @"\\10.20.41.21\sharefolder; <======== 67, 1219 Error Occurs

\\10.20.41.21\ sharefolde ===> opens fine in <Windows File Explorer>.
Please Help me
 
Last edited:
I am trying to upload a file from a shared drive via FTP. <== There is Library or Win API ??
 
Last edited:
Convert the number "67,1219" to hexadecimal. Look for a matching value in winerror.h. If you don't find a matching value, try stripping away the top 16 bits to just be left with the bottom 16 bits. Convert to decimal and then again look in Winerror.h to find a match.

In general, if the current user has access the file share, you don't even need to use your NetworkConnection class. Simply use File.Copy() to copy into the file share. It's when the current user doesn't have access to the fileshare and you need to use a different set of credentials when you need to establish a network file connection.
 

Latest posts

Back
Top Bottom