+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / file uploads in sitefinity

file uploads in sitefinity

5 posts, 0 answered
  1. Mark
    Mark avatar
    24 posts
    Registered:
    16 Jun 2009
    15 Sep 2010
    Link to this post
    Hi,

    If we upload a file bigger than 2mb it gets corrupted,  httpRuntime  is set to its max value sop I am not sure what else to check. The UI states that the limit is 2GB.

    <httpRuntime maxRequestLength="2097151" executionTimeout="3600" />

    Anyone had any similar issues?
  2. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    15 Sep 2010
    Link to this post
    Hi Mark,

    Thank you for using our services.

    We have a bug in the Sitefinity 3.7 SP3 version which does not calculate correctly the size of the uploaded files when they are requested for download. This causes the files to be corrupted when downloaded. We have fixed this issue for our upcoming SP and I am able to provide you with a custom upgrade patch which you can use by following the Upgrade Instructions to upgrade your project. This should resolve issues with this functionality and you should not have to re-upload files.

    Sincerely yours,
    Radoslav Georgiev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Mark
    Mark avatar
    24 posts
    Registered:
    16 Jun 2009
    30 Sep 2010
    Link to this post
    Thanks that worked
  4. Cagri Karahan
    Cagri Karahan avatar
    2 posts
    Registered:
    25 Sep 2012
    29 Oct 2010
    Link to this post
    <%@ Register Assembly="Telerik.Cms.Web.UI" Namespace="Telerik.Cms.Web.UI" TagPrefix="sf" %>
    <%@ Register Assembly="Telerik.Libraries" Namespace="Telerik.Libraries" TagPrefix="sf" %>
    <%@ Register Assembly="Telerik.Cms.Web.UI" Namespace="Telerik.Web.UI.SpamProtection" TagPrefix="sfWeb" %>
     
    <script runat="server" language="c#">
         
        protected override void OnLoad(EventArgs e)
        {
            var cult = System.Threading.Thread.CurrentThread.CurrentUICulture;
            if (cult.Name == "en")
            {
                valUpTest.ErrorMessage = Resources.TagemGlobalResources.uploadFileTypeRestriction_EN;
            }
            if (cult.Name == "tr")
            {
                valUpTest.ErrorMessage = Resources.TagemGlobalResources.uploadFileTypeRestriction_TR;
            }
            // do something here before the load event is raised
            base.OnLoad(e); // the Load event is raised
            // definitely comes after all listeners have been notified.
        }
         
        protected void saveButton1_Click(object sender, EventArgs e)
        {
     
            if (Page.IsValid)
            {
                var contentManager = new Telerik.Cms.Engine.ContentManager("Experts");
                Telerik.Cms.Engine.IContent newContent = contentManager.CreateContent("text/html");
                 
                //newContent.Content = Editor.Content;
                newContent.SetMetaData("Name", Name.Text);
                newContent.SetMetaData("Firstname", Firstname.Text);
                newContent.SetMetaData("Surname", Surname.Text);
                byte[] buffer = null;
     
                if (FileUpload1.HasFile)
                {  
                    //var file = RadUpload1.UploadedFiles[0];
                    var file = FileUpload1.PostedFile;
     
                    //var filePath = "C:\\Program Files\\telerik\\Sitefinity3.7\\WebSites\\tagem\\CV\\";
                    var filePath = Request.PhysicalApplicationPath + "\\CV"; //machine independent
     
                    Regex r = new Regex(@"\.(\w+)$");
                    Match m = r.Match(file.FileName);
                    string fileextension = "";
                    if (m.Success == true)
                    {
                        fileextension = m.Value;
                    }
                    //unique file name
                    string fileName = Name.Text + "_" + DateTime.Today.Year + "_"
                                    + DateTime.Now.Month + "_" + DateTime.Now.Day + fileextension;
                    file.SaveAs(filePath + "\\" + fileName);
                    // we have saved file to disk, now its time to add file to Library
     
                    // create new instance of LibraryManager
                    var libraryManager = new LibraryManager();
                    // get library by specified Name
                    Telerik.Libraries.ILibrary parentLibrary = libraryManager.GetLibrary("CV");
     
                    // create a content item
                    Telerik.Cms.Engine.IContent cvContent = libraryManager.CreateContent(file.ContentType);
                    // specify parent library
                    cvContent.ParentID = parentLibrary.ID;
                    //get the first uploaded file
     
                    buffer = new byte[file.ContentLength];
                    file.InputStream.Read(buffer, 0, file.ContentLength);
                    Telerik.Cms.Engine.IContent content = null;
                    // upload the file
                    try
                    {
                        content = libraryManager.UploadFile(buffer,
                        fileName.Substring(0, fileName.Length - fileextension.Length),
                        fileextension.Substring(1),
                        file.ContentType,
                        file.ContentLength,
                        parentLibrary);
                    }
                    catch (ArgumentException ex)
                    {
                        Response.Write("There is an exception" + ex.Message);
                    }
                    // save the cv as a content of the file
                    cvContent.Content = buffer;
                    Response.Write(cvContent.GetMetaData("Name") + "<br />");
                    string name = fileName.Substring(0, fileName.Length - fileextension.Length);
                    newContent.SetMetaData("CV", name);
     
     
                }
                else
                    newContent.SetMetaData("CV", "-");
                contentManager.SaveContent(newContent);
                 
                var redirectUrl = "~/Home/RosterOfExperts/ApplicationSuccessful.aspx";
     
                try
                {
                    //send informative mail
                    Utilities.Mail mailUtility = new Utilities.Mail();
                    string from = Membership.GetUser("admin").Email;
                    
                    // Get all users in the Administrator role, Add each user to the email.
                    string[] users = Roles.GetUsersInRole("councilMembers");
                    string to = "";
                    foreach (string user in users)
                    {
                        to += Membership.GetUser(user).Email + ",";
                    }
     
                    string body = Name.Text + " TAGEM'e uzman olarak kayıt yaptırmak için başvurdu. Başvuruyu görüntülemek için lütfen giriş yapın: http://www.tbbdm.gov.tr/Home/Profile/Login.aspx";
                    System.Web.Mail.MailFormat mFormat = System.Web.Mail.MailFormat.Html;
     
                    mailUtility.SendMailFromSmtpServer(to, Resources.TagemGlobalResources.smtpUser, Resources.TagemGlobalResources.smtpServer, Resources.TagemGlobalResources.smtpServerPort,
                        Resources.TagemGlobalResources.smtpUser, Resources.TagemGlobalResources.smtpUserPass, body, System.Web.Mail.MailFormat.Html);
                         
                    //mailUtility.SendMailFromSmtpServer(to, "", body, "", "Yeni Uzman Başvurusu", body, System.Web.Mail.MailFormat.Html);
                     
                     
                     
                    /*mailUtility.SendMailFromSmtpServer(to,"Yeni Uzman Başvurusu", body,Resources.TagemGlobalResources.smtpServer,  Resources.TagemGlobalResources.smtpserverport,
                                                            Resources.TagemGlobalResources.smtpUser, Resources.TagemGlobalResources.smtpUserPass, mFormat);
                    */
                }
                catch
                {//mail gönderiminde hata olsa bile başvuruyu kabul edebilmek için 
                     
                }
                var cult = System.Threading.Thread.CurrentThread.CurrentUICulture;
                if (cult.Name == "en")
                    redirectUrl = "~/en/Home/RosterOfExperts/ApplicationSuccessful.aspx";
                Response.Redirect(redirectUrl);
            }
         
        }
    </script>
     
    <div Runat="server" class="workArea insert">
        <telerik:MessageControl runat="server" ID="message1">
            <ItemTemplate>
                <asp:Label runat="server" ID="messageText"></asp:Label>
            </ItemTemplate>
        </telerik:MessageControl>
        <div class="mainForm">
            <fieldset class="set">
                <h4><asp:Label ID="Label1" AssociatedControlID="Name" runat="server">
                    <asp:Literal ID="Literal3" runat="server" Text="<%$Resources:ApplicationName %>"></asp:Literal>
                    * <em id="NameLabel" runat="server"></em>
                </asp:Label></h4>
                    <div class="setIn title">
                        <asp:TextBox ID="Name" Text="" runat="server" CssClass="nameText"></asp:TextBox>
                        <asp:RequiredFieldValidator ID="validator1" runat="server" ControlToValidate="Name"
                                Display="Dynamic" EnableViewState="False" CssClass="validMessage" SetFocusOnError="True" ValidationGroup="ExpertUploadForm" ><strong>
                                <asp:Literal ID="Literal4" runat="server" Text="<%$Resources:NameEmpty %>"></asp:Literal></strong></asp:RequiredFieldValidator>
                    </div>
                <div class="bottom"><div><!-- --></div></div>
                                    <div class="setIn">                   
                                    <ul class="listsiz">
                                        <li>
                                            <asp:Label ID="Label2" AssociatedControlID="FileUpload1" runat="server"><asp:literal ID="Literal1" runat="server" Text="<%$Resources:CV %>"></asp:literal> *<em id="Em1" runat="server"></em></asp:Label>
                                            <asp:FileUpload ID="FileUpload1" runat="server" />
                                            <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="FileUpload1"
                                                    Display="Dynamic" EnableViewState="False" CssClass="validMessage" SetFocusOnError="True" ValidationGroup="ExpertUploadForm" >
                                                    <strong>
                                                    <asp:Literal ID="Literal7" runat="server" Text="<%$Resources:CVEmpty %>"></asp:Literal></strong>
                                            </asp:RequiredFieldValidator>
                                             
                                            <asp:RegularExpressionValidator runat="server" ID="valUpTest" ControlToValidate="FileUpload1"
                                                Display="Dynamic" EnableViewState="False"
                                                ErrorMessage=""
                                                ValidationGroup="ExpertUploadForm"
                                                ValidationExpression=".*(\.doc|\.DOC|\.docx|\.DOCX|\.PDF|\.pdf)$" />
                                            </li>
                                         
                                        <li>
                                            <asp:Label ID="Label7" AssociatedControlID="Firstname" runat="server"><asp:literal ID="Literal25" runat="server" Text="<%$Resources:Firstname %>"></asp:literal> *<em id="FirstnameLabel" runat="server"></em></asp:Label>
                                            <asp:TextBox ID="Firstname" runat="server"></asp:TextBox>
                                            <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="Firstname"
                                                    Display="Dynamic" EnableViewState="False" CssClass="validMessage" SetFocusOnError="True" ValidationGroup="ExpertUploadForm" >
                                                    <strong>
                                                    <asp:Literal ID="Literal12" runat="server" Text="<%$Resources:FirstnameEmpty %>"></asp:Literal></strong>
                                            </asp:RequiredFieldValidator>
                                        </li>
                                        <li>
                                            <asp:Label ID="Label8" AssociatedControlID="Surname" runat="server"><asp:literal ID="Literal26" runat="server" Text="<%$Resources:Surname %>"></asp:literal>*<em id="SurnameLabel" runat="server"></em></asp:Label>
                                            <asp:TextBox ID="Surname" runat="server"></asp:TextBox>
                                            <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="Surname"
                                                    Display="Dynamic" EnableViewState="False" CssClass="validMessage" SetFocusOnError="True" ValidationGroup="ExpertUploadForm" >
                                                    <strong>
                                                    <asp:Literal ID="Literal11" runat="server" Text="<%$Resources:SurnameEmpty %>"></asp:Literal></strong>
                                            </asp:RequiredFieldValidator>
                                        </li>
                                        <li>
                                            <sfWeb:SpamProtector
                                                ID="SpamProtector1"
                                                runat="server"
                                                ValidationGroup="ExpertUploadForm"
                                                CaptchaImageWidth="180"
                                                CaptchaImageHeight="50"
                                                CapcthaInvalidInputMsg="<%$Resources:CaptchaMismatch %>"
                                                EnableCaptcha="true"
                                                CaptchaTextBoxLabel="<%$Resources:CaptchaLabel %>"
                                                CaptchaBackgroundNoise="Medium"
                                                CaptchaLineNoise="Low"
                                                CaptchaFontWarp="Medium"
                                                CaptchaLength="5"
                                                CaptchaPossibleChars="Numbers"
                                                CaptchaMaxTimeout="5"
                                                ErrorMessageCssClass="errorMsg"></sfWeb:SpamProtector>
                                        </li>
                                    </ul>
                                    </div>
                            </fieldset>
                <div class="bottom"><div><!-- --></div></div>
        <p class="button_area bot">
            <asp:Button ID="saveButton1" runat="server" CssClass="CmsButLeft okdark"
                onclick="saveButton1_Click" Text="<%$Resources:CreateThisExpert %>" ValidationGroup="ExpertUploadForm"/>
        </p>
    </div>
    <div class="info" id="divFaq" runat="server">
        <div class="infoBottom">
        </div>
    </div>
    <div class="clear">
        <!-- -->
    </div>
    </div>



    Our files get corrupted even if they are less than 2mb

    we use sitefinity sp3,

    what may be the issue?

    I attached the code, which I changed the extension from .ascx to .gif

    Can you help?

  5. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    29 Oct 2010
    Link to this post
    Hello Cagri,

    Try using the code from this article to upload your items. In Sitefinity 3.7 SP3 there is also a bug when you work with documents like PDF.

    All the best,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Register for webinar
5 posts, 0 answered