Foros del Web » Programación para mayores de 30 ;) » .NET »

Asociaciones de archivo.

Estas en el tema de Asociaciones de archivo. en el foro de .NET en Foros del Web. Hola, Mi programa genera unos archivos, y me gustaría poder asociar los mismos con mi programa mediante una entrada en el registro, de tal forma ...
  #1 (permalink)  
Antiguo 05/02/2010, 18:15
KazerPowa
Invitado
 
Mensajes: n/a
Puntos:
Asociaciones de archivo.

Hola,

Mi programa genera unos archivos, y me gustaría poder asociar los mismos con mi programa mediante una entrada en el registro, de tal forma que el archivo tuviese el icono que yo designe, y que al darle doble click se abra con mi programa.

Esto último genera otra pregunta...como hago para que al abrir un archivo con mi programa, este haga una función? :S

Si alguien ha incluído esto en algún programa con anterioridad, sería muy amable si posteara diciéndome cómo lo hizo...

Gracias!
  #2 (permalink)  
Antiguo 06/02/2010, 05:56
Avatar de freegirl
Colaborador
 
Fecha de Ingreso: octubre-2003
Ubicación: Catalonia
Mensajes: 4.334
Antigüedad: 20 años, 6 meses
Puntos: 156
Respuesta: Asociaciones de archivo.

Código vb:
Ver original
  1. Public Class Example
  2.  
  3.     Public Sub RegisterType()
  4.         Dim fileReg As New FileTypeRegistrar
  5.  
  6.         With fileReg
  7.             .FullPath = Path_To_Executable
  8.             .FileExtension = Extension_To_Register
  9.             .ContentType = "application/" & Your_Description
  10.             .IconIndex = Icon_Index_In_Application
  11.             .IconPath = Path_To_Executable
  12.             .ProperName = Name_Of_Executable
  13.             .CreateType()
  14.         End With
  15.  
  16.     End Sub
  17.  
  18. End Class
  19.  
  20. Public Class FileTypeRegistrar
  21.  
  22. #Region "Properties & Property Variables"
  23.     Private _ProperName As String
  24.     Public Property ProperName() As String
  25.         Get
  26.             Return _ProperName
  27.         End Get
  28.         Set(ByVal Value As String)
  29.             _ProperName = Value
  30.         End Set
  31.     End Property
  32.  
  33.     Private _ContentType As String
  34.     Public Property ContentType() As String
  35.         Get
  36.             Return _ContentType
  37.         End Get
  38.         Set(ByVal Value As String)
  39.             _ContentType = Value
  40.         End Set
  41.     End Property
  42.  
  43.     Private _FullPath As String
  44.     Public Property FullPath() As String
  45.         Get
  46.             Return _FullPath
  47.         End Get
  48.         Set(ByVal Value As String)
  49.             _FullPath = Value
  50.         End Set
  51.     End Property
  52.  
  53.     Private _FileExtension As String
  54.     Public Property FileExtension() As String
  55.         Get
  56.             Return _FileExtension
  57.         End Get
  58.         Set(ByVal Value As String)
  59.             _FileExtension = Value.Replace(".", "")
  60.         End Set
  61.     End Property
  62.  
  63.     Private _IconPath As String
  64.     Public Property IconPath() As String
  65.         Get
  66.             Return _IconPath
  67.         End Get
  68.         Set(ByVal Value As String)
  69.             _IconPath = Value
  70.         End Set
  71.     End Property
  72.  
  73.     Private _IconIndex As Integer
  74.     Public Property IconIndex() As Integer
  75.         Get
  76.             Return _IconIndex
  77.         End Get
  78.         Set(ByVal Value As Integer)
  79.             _IconIndex = Value
  80.         End Set
  81.     End Property
  82. #End Region
  83.  
  84. #Region "Public Methods"
  85.     Public Sub CreateType()
  86.         Dim fileName As String = Path.GetFileNameWithoutExtension(FullPath)
  87.         Dim Ext As String = "." & FileExtension.ToLower
  88.         Dim extKey As RegistryKey = Registry.ClassesRoot.CreateSubKey(Ext)
  89.  
  90.         extKey.SetValue("", fileName)
  91.         extKey.SetValue("Content Type", ContentType)
  92.         extKey.Close()
  93.  
  94.         Dim mainKey As RegistryKey = Registry.ClassesRoot.CreateSubKey(fileName)
  95.         Dim defIconKey As RegistryKey = mainKey.CreateSubKey("DefaultIcon")
  96.  
  97.         defIconKey.SetValue("", IconPath & ", " & IconIndex)
  98.         defIconKey.Close()
  99.  
  100.         Dim shellKey As RegistryKey = mainKey.CreateSubKey("shell")
  101.         Dim OpenKey As RegistryKey = shellKey.CreateSubKey("Open")
  102.         Dim cmdKey As RegistryKey = OpenKey.CreateSubKey("command")
  103.  
  104.         cmdKey.SetValue("", """" & FullPath & " %1""")
  105.         cmdKey.Close()
  106.         OpenKey.Close()
  107.         shellKey.Close()
  108.         mainKey.Close()
  109.  
  110.     End Sub
  111.  
  112.     Public Sub DeleteType()
  113.         Dim fileName As String = Path.GetFileNameWithoutExtension(FullPath)
  114.         Dim Ext As String = "." & FileExtension.ToLower
  115.  
  116.         Registry.ClassesRoot.DeleteSubKey(Ext)
  117.         Registry.ClassesRoot.DeleteSubKey(fileName)
  118.  
  119.     End Sub
  120. #End Region
  121.  
  122. End Class

Fuente: http://bytes.com/topic/net/answers/5...am#post2040365

Etiquetas: Ninguno
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 06:37.