예제 #1
0
        public static WikiFile Create(string fileName, string extension, Guid node, Guid memberGuid, byte[] file, string filetype, List <UmbracoVersion> versions, string dotNetVersion)
        {
            try
            {
                if (ExtensionNotAllowed(extension))
                {
                    return(null);
                }

                var content = Content.GetContentFromVersion(node);
                var member  = new Member(memberGuid);

                if (content != null)
                {
                    var wikiFile = new WikiFile();

                    if (dotNetVersion != null)
                    {
                        wikiFile.DotNetVersion = dotNetVersion;
                    }

                    wikiFile.Name        = fileName;
                    wikiFile.NodeId      = content.Id;
                    wikiFile.NodeVersion = content.Version;
                    wikiFile.FileType    = filetype;
                    wikiFile.CreatedBy   = member.Id;
                    wikiFile.Downloads   = 0;
                    wikiFile.Archived    = false;
                    wikiFile.Versions    = versions;
                    wikiFile.Version     = versions[0];
                    wikiFile.Verified    = false;

                    var path = string.Format("/media/wiki/{0}", content.Id);

                    if (Directory.Exists(HttpContext.Current.Server.MapPath(path)) == false)
                    {
                        Directory.CreateDirectory(HttpContext.Current.Server.MapPath(path));
                    }

                    fileName = fileName.Substring(0, fileName.LastIndexOf('.') + 1);
                    path     = string.Format("{0}/{1}_{2}.{3}", path, DateTime.Now.Ticks, umbraco.cms.helpers.url.FormatUrl(fileName), extension);

                    using (var fileStream = new FileStream(HttpContext.Current.Server.MapPath(path), FileMode.Create))
                        fileStream.Write(file, 0, file.Length);

                    wikiFile.Path = path;
                    wikiFile.SetMinimumUmbracoVersion();
                    wikiFile.Save();

                    return(wikiFile);
                }
            }
            catch (Exception ex)
            {
                Log.Add(LogTypes.Debug, -1, ex.ToString());
            }

            return(null);
        }
예제 #2
0
        public static WikiFile Create(string name, Guid node, Guid memberGuid, HttpPostedFile file, string filetype, List <UmbracoVersion> versions, string dotNetVersion)
        {
            try
            {
                var filename  = file.FileName;
                var extension = filename.Substring(filename.LastIndexOf('.') + 1);

                if (ExtensionNotAllowed(extension))
                {
                    return(null);
                }

                var content = Content.GetContentFromVersion(node);

                var member = new Member(memberGuid);

                if (content != null)
                {
                    var wikiFile = new WikiFile
                    {
                        Name          = name,
                        NodeId        = content.Id,
                        NodeVersion   = content.Version,
                        FileType      = filetype,
                        CreatedBy     = member.Id,
                        Downloads     = 0,
                        Archived      = false,
                        Versions      = versions,
                        Version       = versions[0],
                        Verified      = false,
                        DotNetVersion = dotNetVersion
                    };

                    var path = string.Format("/media/wiki/{0}", content.Id);

                    if (Directory.Exists(HttpContext.Current.Server.MapPath(path)) == false)
                    {
                        Directory.CreateDirectory(HttpContext.Current.Server.MapPath(path));
                    }

                    path = string.Format("{0}/{1}_{2}.{3}", path, DateTime.Now.Ticks, umbraco.cms.helpers.url.FormatUrl(filename), extension);

                    file.SaveAs(HttpContext.Current.Server.MapPath(path));

                    wikiFile.Path = path;

                    // Note: make sure to do this AFTER setting the path, else it will fail
                    wikiFile.SetMinimumUmbracoVersion();

                    wikiFile.Save();

                    return(wikiFile);
                }
            }
            catch (Exception ex)
            {
                Log.Add(LogTypes.Debug, -1, ex.ToString());
            }

            return(null);
        }
예제 #3
0
        public static WikiFile Create(string fileName, string extension, Guid node, Guid memberGuid, byte[] file, string filetype, List<UmbracoVersion> versions)
        {
            try
            {
                if (ExtensionNotAllowed(extension))
                    return null;

                var content = Content.GetContentFromVersion(node);
                var member = new Member(memberGuid);

                if (content != null)
                {
                    var wikiFile = new WikiFile
                    {
                        Name = fileName,
                        NodeId = content.Id,
                        NodeVersion = content.Version,
                        FileType = filetype,
                        CreatedBy = member.Id,
                        Downloads = 0,
                        Archived = false,
                        Versions = versions,
                        Version = versions[0],
                        Verified = false
                    };

                    wikiFile.SetMinimumUmbracoVersion();
                    var path = string.Format("/media/wiki/{0}", content.Id);

                    if (Directory.Exists(HttpContext.Current.Server.MapPath(path)) == false)
                        Directory.CreateDirectory(HttpContext.Current.Server.MapPath(path));

                    fileName = fileName.Substring(0, fileName.LastIndexOf('.') + 1);
                    path = string.Format("{0}/{1}_{2}.{3}", path, DateTime.Now.Ticks, umbraco.cms.helpers.url.FormatUrl(fileName), extension);

                    using (var fileStream = new FileStream(HttpContext.Current.Server.MapPath(path), FileMode.Create))
                        fileStream.Write(file, 0, file.Length);

                    wikiFile.Path = path;
                    wikiFile.Save();

                    return wikiFile;
                }
            }
            catch (Exception ex)
            {
                Log.Add(LogTypes.Debug, -1, ex.ToString());
            }

            return null;
        }
예제 #4
0
        public static WikiFile Create(string name, Guid node, Guid memberGuid, HttpPostedFile file, string filetype, List<UmbracoVersion> versions, string dotNetVersion)
        {
            try
            {
                var filename = file.FileName;
                var extension = filename.Substring(filename.LastIndexOf('.') + 1);

                if (ExtensionNotAllowed(extension))
                    return null;

                var content = Content.GetContentFromVersion(node);

                var member = new Member(memberGuid);

                if (content != null)
                {
                    var wikiFile = new WikiFile
                    {
                        Name = name,
                        NodeId = content.Id,
                        NodeVersion = content.Version,
                        FileType = filetype,
                        CreatedBy = member.Id,
                        Downloads = 0,
                        Archived = false,
                        Versions = versions,
                        Version = versions[0],
                        Verified = false,
                        DotNetVersion = dotNetVersion
                    };

                    var path = string.Format("/media/wiki/{0}", content.Id);

                    if (Directory.Exists(HttpContext.Current.Server.MapPath(path)) == false)
                        Directory.CreateDirectory(HttpContext.Current.Server.MapPath(path));

                    path = string.Format("{0}/{1}_{2}.{3}", path, DateTime.Now.Ticks, umbraco.cms.helpers.url.FormatUrl(filename), extension);

                    file.SaveAs(HttpContext.Current.Server.MapPath(path));

                    wikiFile.Path = path;

                    // Note: make sure to do this AFTER setting the path, else it will fail
                    wikiFile.SetMinimumUmbracoVersion();

                    wikiFile.Save();

                    return wikiFile;
                }

            }
            catch (Exception ex)
            {
                Log.Add(LogTypes.Debug, -1, ex.ToString());
            }

            return null;
        }