Beispiel #1
0
        /// <summary>
        /// Attempts to find the WfDriveInfo object that the path is rooted on.
        /// </summary>
        private static WfDriveInfo FindMatchingDrive(List <WfDriveInfo> list, string path)
        {
            WfDriveInfo ret = null;

            if (list == null)
            {
                return(ret);
            }
            if (list.Count == 0)
            {
                return(ret);
            }
            var temp = new WfPath(path).FullPath;

            ret = list.FirstOrDefault(i => temp.StartsWith(i.MappedUncPath.ToLower()) || temp.StartsWith(i.LocalName.ToLower()));
            return(ret);
        }
Beispiel #2
0
 /// <summary>
 /// Gets the WfDriveInfo which exists at the root of the path given.  If a null is returned, and the path really exists
 /// then this is a pure unc path with no local drive mapping.
 /// </summary>
 public static WfDriveInfo GetWfDriveInfo(string path)
 {
     return(WfDriveInfo.FindMatchingDrive(WfDriveInfo.GetDrives(), path));
 }
Beispiel #3
0
        public static string GetLocalWorkingFolder(string folderName, string preferDrive = "c")
        {
            string ret = @"";

            try
            {
                ret = Path.Combine(@"E:\", folderName);
                //Make sure the drive exists
                if (Directory.Exists(ret))
                {
                    return(ret);
                }
            }
            catch { ret = @""; }

            try
            {
                ret = Path.Combine(@"D:\", folderName);
                //Make sure the drive exists
                if (Directory.Exists(ret))
                {
                    return(ret);
                }
            }
            catch { ret = @""; }

            try
            {
                ret = Path.Combine(@"C:\", folderName);
                //Make sure the drive exists
                if (Directory.Exists(ret))
                {
                    return(ret);
                }
            }
            catch { ret = @""; }

            //Try Creating using prefered drive
            try
            {
                var drive = string.Format("{0}:\\", preferDrive);

                if (WfDriveInfo.GetWfDriveInfo(drive).DriveType == DriveType.Fixed)
                {
                    ret = Path.Combine(drive, folderName);
                    if (Directory.Exists(ret))
                    {
                        return(ret);
                    }
                    else
                    {
                        Directory.CreateDirectory(ret);
                        if (Directory.Exists(ret))
                        {
                            return(ret);
                        }
                    }
                }
            }
            catch { ret = @""; }

            //Ok, back to the basics....
            preferDrive = "c";
            try
            {
                var drive = string.Format("{0}:\\", preferDrive);

                if (WfDriveInfo.GetWfDriveInfo(drive).DriveType == DriveType.Fixed)
                {
                    ret = Path.Combine(drive, folderName);
                    if (Directory.Exists(ret))
                    {
                        return(ret);
                    }
                    else
                    {
                        Directory.CreateDirectory(ret);
                        if (Directory.Exists(ret))
                        {
                            return(ret);
                        }
                    }
                }
            }
            catch { ret = @""; }

            //Just try soemthing!!!
            try
            {
                ret = folderName;
                ret = Path.GetFullPath(ret);
                if (!Directory.Exists(ret))
                {
                    Directory.CreateDirectory(ret);
                }
            }
            catch { ret = @""; }

            return("");
            //try
            //{
            //  ret = @"D:\" + folderName;
            //  if (Directory.Exists(ret))  //Make sure the drive exists
            //  {
            //    ret = @"D:\" + folderName;
            //    if (!Directory.Exists(ret)) { Directory.CreateDirectory(ret); }
            //  }
            //  else { ret = ""; }
            //}
            //catch { ret = ""; }

            //if (ret != @"") { return ret; }

            //try
            //{
            //  ret = @"C:\" + folderName;
            //  if (!Directory.Exists(ret)) { Directory.CreateDirectory(ret); }
            //}
            //catch { ret = @""; }

            //if (ret != @"") { return ret; }

            //try
            //{
            //  ret = folderName;
            //  ret = Path.GetFullPath(ret);
            //  if (!Directory.Exists(ret)) { Directory.CreateDirectory(ret); }
            //}
            //catch { ret = @""; }

            //return ret;
        }