示例#1
0
 /// <summary>Performs last checks before accepting file name from user and closing the dilaog. Also can follow *.lnk links.</summary>
 /// <param name="fileName">Full path of file to be accepted</param>
 /// <param name="followLinks">True to follow *.lnk links</param>
 /// <returns>True when file was accepted, false when it represented link to folder or invalid link (when <paramref name="followLinks"/> is true) of nonexisten file (when <see cref="CheckFileExists"/> is true) or recursive link (when <paramref name="followLinks"/> is false, <see cref="FollowLinks"/> is true and <paramref name="fileName"/> is *.lnk file).</returns>
 private bool AcceptFilename(string fileName, bool followLinks)
 {
     if (followLinks && Path.GetExtension(fileName).ToLower(System.Globalization.CultureInfo.InvariantCulture) == ".lnk")
     {
         try
         {
             ShellLink link = new ShellLink(fileName);
             return(FollowPath(link.File, false));
         }
         catch { return(false); }
     }
     else if (FollowLinks && !followLinks && Path.GetExtension(fileName).ToLower(System.Globalization.CultureInfo.InvariantCulture) == ".lnk")
     {
         return(false);
     }
     else
     {
         if (!CheckFileExists || File.Exists(fileName))
         {
             FileName = fileName;
             return(true);
         }
         return(false);
     }
 }
示例#2
0
 /// <summary>Performs last checks before accepting file name from user and closing the dilaog. Also can follow *.lnk links.</summary>
 /// <param name="fileName">Full path of file to be accepted</param>
 /// <param name="followLinks">True to follow *.lnk links</param>
 /// <returns>True when file was accepted, false when it represented link to folder or invalid link (when <paramref name="followLinks"/> is true) of nonexisten file (when <see cref="CheckFileExists"/> is true) or recursive link (when <paramref name="followLinks"/> is false, <see cref="FollowLinks"/> is true and <paramref name="fileName"/> is *.lnk file).</returns>
 private bool AcceptFilename(string fileName, bool followLinks)
 {
     if (followLinks && Path.GetExtension(fileName).ToLower(System.Globalization.CultureInfo.InvariantCulture) == ".lnk")
     {
         try
         {
             ShellLink link = new ShellLink(fileName);
             return FollowPath(link.File, false);
         }
         catch { return false; }
     }
     else if (FollowLinks && !followLinks && Path.GetExtension(fileName).ToLower(System.Globalization.CultureInfo.InvariantCulture) == ".lnk")
     {
         return false;
     }
     else
     {
         if (!CheckFileExists || File.Exists(fileName))
         {
             FileName = fileName;
             return true;
         }
         return false;
     }
 }