using meta file uploader inside webpart

benyamin jain asked on October 13, 2014 11:25

HI I am creating a user control for the purpose of adding new Tab item to my account web part. i modify the My Account web part code then it is loading my Custom Control in to new tab properly.

(/CMSModules/Ecommerce/Controls/MyDetails/CustomFormControl.ascx)

i have one uploader in this custom form Markup :

<%@ Register TagPrefix="cms" TagName="ImageFile" Src="~/CMSModules/AdminControls/Controls/MetaFiles/File.ascx" %>
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse;">
<tr>
        <td>
            <asp:Label ID="Label" runat="server" CssClass="LableText">Image File :</asp:Label>
        </td>
        <td>
            <cms:ImageFile ID="ucMainImage" runat="server" Enabled="false" />
        </td>
    </tr>
    </tabel>
    <table border="0" cellspacing="0" style="border-collapse: collapse;">
        <tr>
            <td class="SaveButtonCol">
                <asp:Button ID="btnOK" runat="server" OnClick="btnOK_Click" Text="Submit" CssClass="ADOrderButton" />
            </td>
        </tr>
    </table>

in the code file i have this :

 // This class inherited from CMSAdminControl
 protected void Page_Load(object sender, EventArgs e)
{
    if (this.StopProcessing)
    {
        return;
    }
    ucMainImage.ObjectID = 0;
    ucMainImage.ObjectType = ECommerceObjectType.SKU;
    ucMainImage.Category = MetaFileInfoProvider.OBJECT_CATEGORY_IMAGE;
    ucMainImage.SiteID = CMSContext.CurrentSiteID;
    ucMainImage.IsLiveSite = true;
    ucMainImage.Enabled = true;
}

 protected void btnOK_Click(object sender, EventArgs e)
{
     HttpPostedFile file = ucMainImage.PostedFile;
    if ((file != null) && (file.ContentLength > 0))
    {
        // Get file extension
        string extension = Path.GetExtension(file.FileName);

        // Check if file is an image and its extension is allowed
        if (ImageHelper.IsImage(extension) && (String.IsNullOrEmpty(AllowedImageFileExtensions) || FileHelper.CheckExtension(extension, AllowedImageFileExtensions)))
        {

        }
     }
}

The Problem :


when i click on submit button , no file posted and result of" HttpPostedFile file = ucMainImage.PostedFile; " always return null.

i want to know why uploader do not work here and always return null for Posted File.

I test in kenticocms version 6

With best regards

   Please, sign in to be able to submit a new answer.