コード例 #1
0
ファイル: Blog.cs プロジェクト: spbreed/MiniBlog
    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));
    }
コード例 #2
0
ファイル: Site.cs プロジェクト: modulexcite/RazorPub
    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));
    }