Click here to Skip to main content
15,916,692 members
Home / Discussions / C#
   

C#

 
GeneralRe: how to get the system imagelist Pin
noosword20-Jul-04 19:02
noosword20-Jul-04 19:02 
GeneralRe: how to get the system imagelist Pin
Heath Stewart21-Jul-04 3:59
protectorHeath Stewart21-Jul-04 3:59 
GeneralCapturing the desktop Pin
Salman Taseer`19-Jul-04 13:15
Salman Taseer`19-Jul-04 13:15 
GeneralRe: Capturing the desktop Pin
Nick Parker19-Jul-04 17:16
protectorNick Parker19-Jul-04 17:16 
GeneralTag name of the root element of the XML data file Pin
Flack19-Jul-04 13:04
Flack19-Jul-04 13:04 
GeneralRe: Tag name of the root element of the XML data file Pin
Dave Kreskowiak19-Jul-04 15:32
mveDave Kreskowiak19-Jul-04 15:32 
GeneralRe: Tag name of the root element of the XML data file Pin
Flack19-Jul-04 16:05
Flack19-Jul-04 16:05 
GeneralRe: Tag name of the root element of the XML data file Pin
Nick Parker19-Jul-04 17:11
protectorNick Parker19-Jul-04 17:11 
GeneralRe: Tag name of the root element of the XML data file Pin
Heath Stewart20-Jul-04 4:01
protectorHeath Stewart20-Jul-04 4:01 
GeneralRe: Tag name of the root element of the XML data file Pin
Heath Stewart20-Jul-04 4:04
protectorHeath Stewart20-Jul-04 4:04 
GeneralAccessing Parallel Port Pin
ahmedadelfarid19-Jul-04 11:32
ahmedadelfarid19-Jul-04 11:32 
GeneralRe: Accessing Parallel Port Pin
Dave Kreskowiak19-Jul-04 15:31
mveDave Kreskowiak19-Jul-04 15:31 
GeneralRe: Accessing Parallel Port Pin
eggie519-Jul-04 18:23
eggie519-Jul-04 18:23 
Generaltrap state changes (standbye, hibernate, etc) Pin
vista2719-Jul-04 11:31
vista2719-Jul-04 11:31 
GeneralRe: trap state changes (standbye, hibernate, etc) Pin
Heath Stewart19-Jul-04 11:45
protectorHeath Stewart19-Jul-04 11:45 
GeneralRe: trap state changes (standbye, hibernate, etc) Pin
vista2719-Jul-04 13:57
vista2719-Jul-04 13:57 
GeneralRe: trap state changes (standbye, hibernate, etc) Pin
Heath Stewart20-Jul-04 3:40
protectorHeath Stewart20-Jul-04 3:40 
GeneralCultureInfo for unsupported Culture Pin
Colin Angus Mackay19-Jul-04 11:25
Colin Angus Mackay19-Jul-04 11:25 
GeneralRe: CultureInfo for unsupported Culture Pin
Heath Stewart19-Jul-04 11:40
protectorHeath Stewart19-Jul-04 11:40 
GeneralRe: CultureInfo for unsupported Culture Pin
Colin Angus Mackay20-Jul-04 2:39
Colin Angus Mackay20-Jul-04 2:39 
GeneralRe: CultureInfo for unsupported Culture Pin
Heath Stewart20-Jul-04 3:56
protectorHeath Stewart20-Jul-04 3:56 
This code gets a manifest resource stream (identitied by the const StreamResource) from a satellite assembly. Unfortunately, you'll still need a valid CultureInfo (sorry, it's been a while since I wrote this; it might still help, though):
public static Stream GetZipResourceStream(CultureInfo culture)
{
  // Get a reference to this assembly.
  Assembly asm = typeof(SiteBuilder).Assembly;

  // Get the neutral resources language, if any.
  CultureInfo neutral = GetNeutralResourcesLanguage(asm);
  if (culture == null || !culture.Equals(neutral))
  {
    // Get the satellite contract version, or use this assembly's version.
    Version v = GetSatelliteContractVersion(asm);
    if (v == null) v = asm.GetName().Version;

    try
    {
      // Now get the satellite assembly for the culture and version.
      asm = asm.GetSatelliteAssembly(culture, v);
    }
    catch
    {
      // Try to get the invariant culture's satellite assembly and version.
      try
      {
        asm = asm.GetSatelliteAssembly(culture.Parent, v);
      }
      catch {}
    }
  }

  // Get the manifest resource stream.
  Stream s = asm.GetManifestResourceStream(SiteResource);
  return s;
}

internal static CultureInfo GetNeutralResourcesLanguage(Assembly a)
{
  if (a == null) throw new ArgumentNullException("a");

  // If the assembly is 'mscorlib.dll', return an invariant culture.
  if (a == typeof(object).Assembly)
    return CultureInfo.InvariantCulture;

  // Try to find the NeutralResourcesLanguageAttribute.
  NeutralResourcesLanguageAttribute[] attrs =
    (NeutralResourcesLanguageAttribute[])
    a.GetCustomAttributes(typeof(NeutralResourcesLanguageAttribute), false);

  // If the attribute wasn't found, return an invariant culture.
  if (attrs.Length == 0) return CultureInfo.InvariantCulture;

  try
  {
    // If the name is valid, return a CultureInfo from it.
    return new CultureInfo(attrs[0].CultureName);
  }
  catch (ThreadAbortException)
  {
    throw;
  }
  catch (Exception ex)
  {
    throw new ArgumentException(
	  BLR.FormatString("InvalidNeutralResourcesLanguageCulture",
      a.ToString(), attrs[0].CultureName), "a", ex);
  }
}

internal static Version GetSatelliteContractVersion(Assembly a)
{
  if (a == null) throw new ArgumentNullException("a");

  // If the assembly is 'mscorlib.dll', return null.
  if (a == typeof(object).Assembly)
    return null;

  SatelliteContractVersionAttribute[] attrs =
    (SatelliteContractVersionAttribute[])
    a.GetCustomAttributes(typeof(SatelliteContractVersionAttribute), false);

  // If the attribute wasn't found, return null.
  if (attrs.Length == 0) return null;

  try
  {
    // If the version is valid, return a Version from it.
    return new Version(attrs[0].Version);
  }
  catch (Exception ex)
  {
    throw new ArgumentException(
	  BLR.FormatString("InvalidSatelliteContractVersion",
      a.ToString(), attrs[0].Version), "a", ex);
  }
}


 

Microsoft MVP, Visual C#
My Articles
GeneralRe: CultureInfo for unsupported Culture Pin
Colin Angus Mackay20-Jul-04 10:45
Colin Angus Mackay20-Jul-04 10:45 
GeneralVery simple search on a form Pin
janigorse19-Jul-04 10:59
janigorse19-Jul-04 10:59 
GeneralRe: Very simple search on a form Pin
Heath Stewart19-Jul-04 11:23
protectorHeath Stewart19-Jul-04 11:23 
Generalintegrate context menu with shell Pin
goooooooogle19-Jul-04 9:52
goooooooogle19-Jul-04 9:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.