Dev2.PathOperations.ActivityIOFactory.CreatePathFromString C# (CSharp) Method

CreatePathFromString() public static method

Return an IActivityIOPath based upont the path string
public static CreatePathFromString ( string path ) : IActivityIOPath
path string
return IActivityIOPath
        public static IActivityIOPath CreatePathFromString(string path)
        {
            return CreatePathFromString(path, string.Empty, string.Empty);
        }

Same methods

ActivityIOFactory::CreatePathFromString ( string path, bool IsNotCertVerifiable ) : IActivityIOPath
ActivityIOFactory::CreatePathFromString ( string path, bool isNotCertVerifiable, string privateKeyFile = "" ) : IActivityIOPath
ActivityIOFactory::CreatePathFromString ( string path, string user, string pass ) : IActivityIOPath
ActivityIOFactory::CreatePathFromString ( string path, string user, string pass, bool IsNotCertVerifiable ) : IActivityIOPath
ActivityIOFactory::CreatePathFromString ( string path, string user, string pass, bool isNotCertVerifiable, string privateKeyFile = "" ) : IActivityIOPath
ActivityIOFactory::CreatePathFromString ( string path, string user, string pass, string privateKeyFile = "" ) : IActivityIOPath

Usage Example

        public int Put(Stream src, IActivityIOPath dst, Dev2CRUDOperationTO args, string whereToPut, List <string> filesToCleanup)
        {
            int result = -1;

            using (src)
            {
                //2013.05.29: Ashley Lewis for bug 9507 - default destination to source directory when destination is left blank or if it is not a rooted path
                if (!Path.IsPathRooted(dst.Path))
                {
                    //get just the directory path to put into
                    if (whereToPut != null)
                    {
                        //Make the destination directory equal to that directory
                        dst = ActivityIOFactory.CreatePathFromString(whereToPut + "\\" + dst.Path, dst.Username, dst.Password);
                    }
                }

                if ((args.Overwrite) || (!args.Overwrite && !FileExist(dst)))
                {
                    if (!RequiresAuth(dst))
                    {
                        using (src)
                        {
                            File.WriteAllBytes(dst.Path, src.ToByteArray());
                            result = (int)src.Length;
                        }
                    }
                    else
                    {
                        // handle UNC path
                        SafeTokenHandle safeTokenHandle;
                        bool            loginOk = LogonUser(ExtractUserName(dst), ExtractDomain(dst), dst.Password, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, out safeTokenHandle);


                        if (loginOk)
                        {
                            using (safeTokenHandle)
                            {
                                WindowsIdentity newID = new WindowsIdentity(safeTokenHandle.DangerousGetHandle());
                                using (WindowsImpersonationContext impersonatedUser = newID.Impersonate())
                                {
                                    // Do the operation here

                                    using (src)
                                    {
                                        File.WriteAllBytes(dst.Path, src.ToByteArray());
                                        result = (int)src.Length;
                                    }


                                    // remove impersonation now
                                    impersonatedUser.Undo();
                                }
                            }
                        }
                        else
                        {
                            // login failed
                            throw new Exception("Failed to authenticate with user [ " + dst.Username + " ] for resource [ " + dst.Path + " ] ");
                        }
                    }
                }
            }

            return(result);
        }
All Usage Examples Of Dev2.PathOperations.ActivityIOFactory::CreatePathFromString