Mostrando las entradas con la etiqueta web. Mostrar todas las entradas
Mostrando las entradas con la etiqueta web. Mostrar todas las entradas

martes, 11 de febrero de 2014

Función para sacar el nombre corto de un archivo en C#.

  Buenos días hoy les traigo una función para C# muy útil para acortar los nombres de los archivos, esta muy función me sirvió para abrir archivos .DBF ya que el controlador no puede abrir archivos de más de 8 caracteres. Esta función hace uso de kernel32.dll, el resultado sería archvi~1

La función la encontré y la comparto para que sea más fácil su búsqueda.

public static string GetShortFileName(string fileDirectory, string fileNameWithExtension)
{
    StringBuilder temp = new StringBuilder(255);

    string path = System.IO.Path.Combine(fileDirectory, fileNameWithExtension);

    int n = GetShortPathName(path, temp, 255);

    if (n == 0)
        throw new NotImplementedException();

    string extension = System.IO.Path.GetExtension(path);

    return ((temp.ToString().Split('\\')).Last()).ToLower();//.Replace(extension, string.Empty);
}

[System.Runtime.InteropServices.DllImport("kernel32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto)]
public static extern int GetShortPathName(
    [System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPTStr)]    
        string path,
    [System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPTStr)]    
        StringBuilder shortPath,
    int shortPathLength);

Si también tienen problemas para abrir un .DBF esto podría servirles, claro partiendo de que ya tienen la conexión
string nomFile = GetShortFileName(Path.GetDirectoryName(FilePath), Path.GetFileName(FilePath));
nomFile = nomFile.Substring(0, nomFile.Length - 4);
                
OleDbDataAdapter dadp = new OleDbDataAdapter("select * from [" + nomFile + "#DBF];", con);

viernes, 6 de septiembre de 2013

¿Como saber si las cookies están habilitadas del lado del cliente?

Esto se puede comprobar en el Javascript con el objeto con la propiedad cookieEnabled del objeto navigator.


function are_cookies_enabled() {
        var cookieEnabled = (navigator.cookieEnabled) ? true : false;

        if (typeof navigator.cookieEnabled == "undefined" && !cookieEnabled) {
            document.cookie = "testcookie";
            cookieEnabled = (document.cookie.indexOf("testcookie") != -1) ? true : false;
        }
        return (cookieEnabled);
    }

También se puede saber creando una cookie y comprobar si el navegador lo hizo o no.






Fuentes:
http://stackoverflow.com/questions/2167310/how-to-show-a-message-only-if-cookies-are-disabled-in-browser
http://stackoverflow.com/questions/531393/how-to-detect-server-side-whether-cookies-are-disabled
http://es.softuses.com/70356