Esempio n. 1
0
    public static string SaveFileToDisk(byte[] bytes, string extension)
    {
        string relative = "~/posts/files/" + Guid.NewGuid();

        if (string.IsNullOrWhiteSpace(extension))
        {
            extension = ".bin";
        }
        else
        {
            extension = "." + extension.Trim('.');
        }

        relative += extension;

        string file = HostingEnvironment.MapPath(relative);

        File.WriteAllBytes(file, bytes);

        var cruncher = new ImageCruncher.Cruncher();

        cruncher.CrunchImages(file);

        return(VirtualPathUtility.ToAbsolute(relative));
    }
Esempio n. 2
0
    public static string SaveFileToDisk(byte[] bytes, string filename, string extension)
    {
        string relative = "~/files/";

        if (!extension.Contains("md"))
        {
            relative += "media/";
        }

        if (string.IsNullOrWhiteSpace(extension))
        {
            extension = ".bin";
        }
        else
        {
            extension = "." + extension.Trim('.');
        }

        relative += filename + extension;

        string file = HostingEnvironment.MapPath(relative);

        File.WriteAllBytes(file, bytes);

        if (extension == ".png" || extension == ".jpg")
        {
            var cruncher = new ImageCruncher.Cruncher();
            cruncher.CrunchImages(file);
        }

        return(VirtualPathUtility.ToAbsolute(relative));
    }