private void DownloadFile(System.Web.HttpContext context, CmsContent content, String filename)
        {
            CmsContentField mimeTypeField = content.FindField("mimetype");
            string mimeType = "application/octet-stream";
            if (mimeTypeField != null)
                mimeType = mimeTypeField.Value;

            Data.Guid siteGuid = CurrentSite.Guid;
            ContentFileUploadImpl filehandler = new ContentFileUploadImpl();
            StorageFile fileinfo = filehandler.GetInfo(siteGuid, filename);

            context.Response.Clear();
            context.Response.ClearHeaders();
            context.Response.ClearContent();
            context.Response.ContentType = mimeType;
            context.Response.AppendHeader("Content-Disposition", "attachment;filename=\"" + filename + "\"");
            context.Response.AppendHeader("Content-Length", fileinfo.Size.ToString());
            context.Response.AppendHeader("Content-Transfer-Encoding", "binary");
            context.Response.Expires = 60;
            context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
            context.Response.Cache.SetMaxAge(TimeSpan.FromMinutes(0));
            filehandler.Read(siteGuid,filename,context.Response.OutputStream);

            context.Response.Flush();
            context.Response.Close();
            context.Response.End();
        }
Exemple #2
0
        protected void BtnAddContent_Click(object sender, EventArgs e)
        {
            String typeGuid = this.LstContentTypes.SelectedValue;
            CmsContentType type = ContentManager.Instance.GetContentType(typeGuid);
            if (type != null)
            {
                Boolean required = Boolean.Parse(this.RequireRegistration.SelectedValue);
                if (required)
                {
                    if (String.IsNullOrWhiteSpace(this.RegistrationPage.Text))
                        throw new ArgumentException("You must select a registration page if the content requires registration");
                }

                CmsContent item = new CmsContent();
                item.PublishDate = UtcDateTime.Now;
                item.ExpireDate = UtcDateTime.Now.AddYears(100);
                item.SubscriptionId = CurrentSite.Guid.Value;
                item.Guid = System.Guid.NewGuid().ToString();
                item.Culture = CurrentSite.Culture;
                item.Author = LoggedInUser.Username;
                item.IsApproved = false;
                item.LastSaved = UtcDateTime.Now;
                item.RequiresRegistration = required;
                item.RegistrationPage = this.RegistrationPage.SelectedValue;
                item.Content = this.TxtEditor.Text;
                item.ContentType = type;

                CmsContent content = ContentManager.Instance.CreateContent(item, this.ControlTable);
                String filterId = "";
                if (content != null)
                {
                    //TODO Attach tags to the content
                    filterId = content.ContentType.Guid;
                }
                Response.Redirect("./Default.aspx?s=1&filter=" + filterId, true);
            }
        }
        private void PopulateFields(Data.Guid siteGuid, Control parent, CmsContent item, String oldFilename)
        {
            if (item.ContentType.IsFileType)
            {
                FileUpload upload = (FileUpload)ControlHelper.FindRecursive(parent, "fileupload");
                if ((!upload.HasFile) && (oldFilename == null))
                    throw new ArgumentException("This content type requires that a file be uploaded");

                if (upload.HasFile)
                {
                    byte[] data = upload.FileBytes;
                    String filename = (oldFilename == null) ? upload.FileName : oldFilename;
                    String mimeType = upload.PostedFile.ContentType;

                    Boolean overwrite = false;
                    if (!String.IsNullOrWhiteSpace(oldFilename))
                        overwrite = true;

                    if (!ContentFileUploadImpl.IsValidFileType(filename))
                        throw new ArgumentException("The specified filetype is not currently supported by the CMS. Valid file types are:" + ContentFileUploadImpl.ValidExtensionsString);

                    ContentFileUploadImpl handler = new ContentFileUploadImpl();
                    handler.Save(siteGuid,data, filename, overwrite);

                    CmsContentField filenameField = new CmsContentField();
                    CmsContentField mimeTypeField = new CmsContentField();

                    filenameField.Name = "filename";
                    filenameField.ObjectType = "System.String";
                    filenameField.Value = filename;
                    filenameField.Parent = item;

                    mimeTypeField.Name = "mimetype";
                    mimeTypeField.ObjectType = "System.String";
                    mimeTypeField.Value = mimeType;
                    mimeTypeField.Parent = item;

                    item.AddField(filenameField);
                    item.AddField(mimeTypeField);
                }
            }

            //Loop through each expected id and build up the CMS content item
            IList<CmsContentTypeField> typeFields = ContentManager.Instance.GetContentTypeFields(item.ContentType.Guid);
            foreach (CmsContentTypeField typeField in typeFields)
            {
                String id = ContentWebControlManager.GetControlId(typeField);
                String[] parts = id.Split('_');
                String objectType = parts[1];
                String propertyName = parts[2];

                String result = null;
                Control control = ControlHelper.FindRecursive(parent, id);
                switch (objectType.ToLower())
                {
                    case CmsContentTypeField.Textbox:
                    case CmsContentTypeField.Textarea:
                        result = ContentWebControlManager.GetTextboxValue(control);
                        break;
                    case CmsContentTypeField.Datetime:
                        result = ContentWebControlManager.GetDateTimeValue(control);
                        break;
                    case CmsContentTypeField.Dropdown:
                        result = ContentWebControlManager.GetDropdownValue(control);
                        break;
                }

                CmsContentField field = new CmsContentField();
                field.Name = typeField.SystemName;
                field.ObjectType = typeField.ObjectType;
                field.Value = result;

                field.Parent = item;
                item.AddField(field);
            }
        }
        public void Update(CmsContent item, Table table)
        {
            //Updating always unapproved the item
            item.IsApproved = false;

            //Save the filename, so we can restore it
            String filename = null;
            if (item.ContentType.IsFileType)
                filename = item.FindField("filename").Value;

            //Remove all of the existing items
            foreach (CmsContentField field in item.Fields)
            {
                if (!(field.Name.Equals("filename")) &&
                     !(field.Name.Equals("mimetype")))
                {
                    item.RemoveField(field);
                }
            }
            PopulateFields(item.SubscriptionId,table, item, filename);

            Save(item);
        }
        public void Save(CmsContent item)
        {
            CmsContentDao dao = new CmsContentDao();
            using (Transaction tx = new Transaction())
            {
                dao.Save<CmsContent>(item);
                tx.Commit();
            }

            SitePageCacheRefreshInvoker.InvokeRefresh(item.SubscriptionId, SitePageRefreshRequest.PageRefreshType.All);
        }
 public void Delete(CmsContent content)
 {
     if (content != null)
     {
         CmsContentDao dao = new CmsContentDao();
         using (Transaction tx = new Transaction())
         {
             dao.Delete<CmsContent>(content);
             tx.Commit();
         }
     }
 }
        public CmsContent CreateContent(CmsContent content, System.Web.UI.WebControls.Table dynamicControls)
        {
            if (content.SubscriptionId == null)
                throw new ApplicationException("The subscription id must not be null. This is a programming error.");

            IList<CmsContentField> fields = new List<CmsContentField>();
            PopulateFields(content.SubscriptionId,dynamicControls, content, null);

            CmsContentDao dao = new CmsContentDao();
            using (Transaction tx = new Transaction())
            {
                dao.Save<CmsContent>(content);
                tx.Commit();
            }

            return content;
        }
        private string BlockMatchEvaluator(Match match)
        {
            String contentType = match.Groups["id"].Value;
            String orderBy = match.Groups["orderby"].Value;
            String limitBy = match.Groups["limit"].Value;
            String block = match.Groups["block"].Value;
            String where = match.Groups["where"].Value;

            String orderByField = null;
            String orderByDirection = "asc";
            Match orderByMatch = OrderBy.Match(orderBy);
            if (orderByMatch.Success)
            {
                orderByField = orderByMatch.Groups["field"].Value;
                orderByDirection = orderByMatch.Groups["direction"].Value;
            }

            int limit = 0;
            Match limitMatch = Limit.Match(limitBy);
            if (limitMatch.Success)
            {
                limit = Int32.Parse(limitMatch.Value);
            }

            //Perform the search for the content type
            ContentQueryBuilder query = new ContentQueryBuilder();
            IList<CmsContent> results = query.SetSubscriptionGuid(CurrentSite.Guid)
                                             .SetContentType(contentType)
                                             .SetOrderBy(orderByField, orderByDirection)
                                             .SetLimit(limit)
                                             .SetWhereClause(where)
                                             .SetApprovedOnly(CurrentSite.IsProductionHost)
                                             .ExecuteQuery();

            StringBuilder replacement = new StringBuilder();

            this.loadedContentType = contentType;
            foreach (CmsContent item in results)
            {
                this.loadedContent = item;
                String result = Field.Replace(block, new MatchEvaluator(FieldMatchEvaluator));

                replacement.Append(result);
            }
            this.loadedContentType = null;
            this.loadedContent = null;

            return replacement.ToString();
        }
        private void loadContentFromQuerystring(String contentType)
        {
            String guid = WebRequestContext.Instance.Request[contentType];

            //If the guid is null, check if they used the default identifier instead of a content type identifier
            if (guid == null)
                guid = WebRequestContext.Instance.Request.QueryString["cid"];

            if (guid != null)
            {
                CmsContentDao dao = new CmsContentDao();
                loadedContent = dao.FindByGuid(CurrentSite.Guid, guid);
                loadedContentType = contentType;
            }
        }
        private void DeployContent(SitePackage sitepackage, Data.Guid guid)
        {
            foreach (SiteContent ct in sitepackage.SiteContent)
            {
                CmsContent newcontent = new CmsContent();
                CmsContent content = ct.Content;
                IList<CmsContentField> fields = new List<CmsContentField>(content.Fields);

                newcontent.Guid = System.Guid.NewGuid().ToString();
                newcontent.SubscriptionId = guid.Value;
                newcontent.ContentType = content.ContentType;
                newcontent.Content = content.Content;
                newcontent.Culture = content.Culture;
                newcontent.ExpireDate = content.ExpireDate;
                newcontent.IsApproved = content.IsApproved;
                newcontent.LastSaved = content.LastSaved;
                newcontent.PublishDate = content.PublishDate;
                newcontent.RegistrationPage = content.RegistrationPage;
                newcontent.RequiresRegistration = content.RequiresRegistration;
                foreach (CmsContentField field in fields)
                {
                    CmsContentField newfield = new CmsContentField();
                    newfield.Name = field.Name;
                    newfield.ObjectType = field.ObjectType;
                    newfield.Value = field.Value;

                    newcontent.AddField(newfield);
                }

                ContentManager.Instance.Save(newcontent);
            }
        }