private static string GetFileAssociationCore(string path, AssociationAttributes attributes, AssociationString associationType) { if (Utils.IsNullOrWhiteSpace(path)) { throw new ArgumentNullException("path"); } attributes = attributes | AssociationAttributes.NoTruncate | AssociationAttributes.RemapRunDll; uint bufferSize = NativeMethods.MaxPath; StringBuilder buffer; uint retVal; do { buffer = new StringBuilder((int)bufferSize); // AssocQueryString() // In the ANSI version of this function, the name is limited to 248 characters. // To extend this limit to 32,767 wide characters, call the Unicode version of the function and prepend "\\?\" to the path. // 2014-02-05: MSDN does not confirm LongPath usage but a Unicode version of this function exists. // However, the function fails when using Unicode format. retVal = NativeMethods.AssocQueryString(attributes, associationType, path, null, buffer, out bufferSize); // No Exception is thrown, just return empty string on error. //switch (retVal) //{ // // 0x80070483: No application is associated with the specified file for this operation. // case 2147943555: // case Win32Errors.E_POINTER: // case Win32Errors.S_OK: // break; // default: // NativeError.ThrowException(retVal); // break; //} } while (retVal == Win32Errors.E_POINTER); return(buffer.ToString()); }
private static string GetFileAssociationCore(string path, AssociationAttributes attributes, AssociationString associationType) { if (Utils.IsNullOrWhiteSpace(path)) { throw new ArgumentNullException("path"); } attributes = attributes | AssociationAttributes.NoTruncate | AssociationAttributes.RemapRunDll; uint bufferSize = NativeMethods.MaxPath; StringBuilder buffer; uint retVal; do { buffer = new StringBuilder((int)bufferSize); // AssocQueryString() // 2014-02-05: MSDN does not confirm LongPath usage but a Unicode version of this function exists. // 2015-07-17: This function does not support long paths. retVal = NativeMethods.AssocQueryString(attributes, associationType, path, null, buffer, out bufferSize); // No Exception is thrown, just return empty string on error. //switch (retVal) //{ // // 0x80070483: No application is associated with the specified file for this operation. // case 2147943555: // case Win32Errors.E_POINTER: // case Win32Errors.S_OK: // break; // default: // NativeError.ThrowException(retVal); // break; //} } while (retVal == Win32Errors.E_POINTER); return(buffer.ToString()); }
private static string GetFileAssociationInternal(string path, AssociationAttributes attributes, AssociationString associationType) { if (Utils.IsNullOrWhiteSpace(path)) throw new ArgumentNullException("path"); attributes = attributes | AssociationAttributes.NoTruncate | AssociationAttributes.RemapRunDll; uint bufferSize = NativeMethods.MaxPath; StringBuilder buffer; uint retVal; do { buffer = new StringBuilder((int)bufferSize); // AssocQueryString() // In the ANSI version of this function, the name is limited to 248 characters. // To extend this limit to 32,767 wide characters, call the Unicode version of the function and prepend "\\?\" to the path. // 2014-02-05: MSDN does not confirm LongPath usage but a Unicode version of this function exists. // However, the function fails when using Unicode format. retVal = NativeMethods.AssocQueryString(attributes, associationType, path, null, buffer, out bufferSize); // No Exception is thrown, just return empty string on error. //switch (retVal) //{ // // 0x80070483: No application is associated with the specified file for this operation. // case 2147943555: // case Win32Errors.E_POINTER: // case Win32Errors.S_OK: // break; // default: // NativeError.ThrowException(retVal); // break; //} } while (retVal == Win32Errors.E_POINTER); return buffer.ToString(); }