Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jigs 40 posts 63 karma points
    Aug 01, 2012 @ 09:46
    Jigs
    0

    Umbraco 4.8 - Parameter is not valid - error when tryin to upload media files programetically..

    hi,

    i am using umbraco 4.8 ...and trying to upload image files programetically to media section ... using user control ....

    everything working fine if i am creating node and uploading images to node sub child ...as a upload file ...

    but when i am trying to upload same images to media folder .... it gives me this error ....

    if i chnage the order of the code ...means creating images to media folder then it gives me error when i creating node to content ,,,,

    not sure  what is wrong .....

    here is trace error...

    also i am using this code to create node and media files to media sections.....

    any help would be appriciated ...

    cheers,

    jigs

  • Jigs 40 posts 63 karma points
    Aug 02, 2012 @ 02:21
    Jigs
    0

    Error:

    Server Error in '/' Application.


    Parameter is not valid.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.ArgumentException: Parameter is not valid.

    Source Error:

    Line 67: 
    Line 68:                 var mediaImage = Media.MakeNew(fileName, fileMediaType, user, folder.Id);
    Line 69: mediaImage.getProperty("umbracoFile").Value = file; Line 70:             }
    Line 71:             


    Source File: C:\My VS Project\umbraco4-clean\Training.Level2-Clean\Training.Level2\usercontrols\CommentForm.ascx.cs    Line: 69

    Stack Trace:

    [ArgumentException: Parameter is not valid.]
       System.Drawing.Image.FromStream(Stream stream, Boolean useEmbeddedColorManagement, Boolean validateImageData) +1157767
       System.Drawing.Image.FromStream(Stream stream) +8
       umbraco.cms.businesslogic.Files.UmbracoFile.GetDimensions() +103
       umbraco.cms.businesslogic.Files.UmbracoFile.Resize(Int32 maxWidthHeight, String fileNameAddition) +54
       umbraco.cms.businesslogic.datatype.FileHandlerData.set_Value(Object value) +921
       umbraco.cms.businesslogic.property.Property.set_Value(Object value) +40
       Training.Level2.usercontrols.CommentForm.postStatus(Object sender, EventArgs e) in C:\My VS Project\umbraco4-clean\Training.Level2-Clean\Training.Level2\usercontrols\CommentForm.ascx.cs:69
       System.Web.UI.WebControls.Button.OnClick(EventArgs e) +118
       System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +112
       System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
       System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
       System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563
    



    Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272

  • Jigs 40 posts 63 karma points
    Aug 02, 2012 @ 02:22
    Jigs
    0

    Code:  i am using is ....

                 for (int i = 0; i < Request.Files.Count; i++)
                {
                    HttpPostedFile file = Request.Files[i];

                    var fileType = DocumentType.GetByAlias("StatusUpdateFile");
                    var fileName = "File-" + DateTime.Now.Ticks.ToString();

                    var statusFile = Document.MakeNew(fileName, fileType, user, d.Id);
                    statusFile.getProperty("upload").Value = file;

                    statusFile.Publish(user);

                    umbraco.library.UpdateDocumentCache(statusFile.Id);
                }

                // adding images to media folder

                var mt = MediaType.GetByAlias("Folder");
                var folder = Media.MakeNew(name, mt, user, -1);

                for (int i = 0; i < Request.Files.Count; i++)
                {
                    HttpPostedFile file = Request.Files[i];

                    var fileMediaType = MediaType.GetByAlias("File");
                    var fileName = "File-" + DateTime.Now.Ticks.ToString();

                    var mediaImage = Media.MakeNew(fileName, fileMediaType, user, folder.Id);
                    mediaImage.getProperty("umbracoFile").Value = file;
                }

     

Please Sign in or register to post replies

Write your reply to:

Draft