Beispiel #1
0
        public ActionResult Create(string template, string alternate, string returnUrl)
        {
            if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to create templates")) && !Request.IsLocal)
            {
                return(new HttpUnauthorizedResult());
            }

            alternate = alternate.Replace("__", "-").Replace("_", ".");

            var currentTheme      = _themeManager.GetRequestTheme(Request.RequestContext);
            var alternateFilename = Server.MapPath(Path.Combine(currentTheme.Location, currentTheme.Id, "Views", alternate));

            // use same extension as template, or ".cshtml" if it's a code template))
            if (_webSiteFolder.FileExists(template))
            {
                alternateFilename += Path.GetExtension(template);

                using (var stream = System.IO.File.Create(alternateFilename)) {
                    _webSiteFolder.CopyFileTo(template, stream);
                }
            }
            else
            {
                alternateFilename += ".cshtml";
                using (System.IO.File.Create(alternateFilename)) {}
            }

            return(this.RedirectLocal(returnUrl));
        }
Beispiel #2
0
            public Stream GetStream()
            {
                var stream = new MemoryStream();

                _webSiteFolder.CopyFileTo(_virtualPath, stream);
                stream.Seek(0, SeekOrigin.Begin);
                return(stream);
            }