Problem writing metadata to jpg

Last post 04-27-2009 9:17 AM by Kosko. 0 replies.

Sort Posts:

  • Problem writing metadata to jpg

    04-27-2009, 9:17 AM
    • Member
      point Member
    • Kosko
    • Member since 03-12-2009, 3:32 PM
    • Posts 4

    Hi,

    I have a small form app that imports a image that a user browses to and adds the metadata to that image based on information provided in the form.

    The process does work, it just doesn't write the description properties. It writes to the copywrite tag just fine, as well as create and transport the new image between servers.

    Any help is always appreciated.  The code that is supposed to write the metadata is:

    if(this.sErrors == "") {
                    try {
                        ASCIIEncoding oEncoder = new ASCIIEncoding();
                        string sNewFile = Guid.NewGuid().ToString("D")+".jpg";
                        string sFile = Server.MapPath("tmp\\upload-"+sNewFile);
                        PropertyItem oProp;
                        PictureLocation.SaveAs(sFile);
                       
                        Image imgUpload = Image.FromFile(sFile);
                        foreach(PropertyItem oProperty in imgUpload.PropertyItems) {
                            imgUpload.RemovePropertyItem(oProperty.Id);
                        }
                       
                        oProp = CreatePropertyItem(0x0320, PictureCaption.Text);
                        imgUpload.SetPropertyItem(oProp);
                       
                        oProp = CreatePropertyItem(0x013B, FirstName.Text+" "+LastName.Text+" ("+EMail.Text+")");
                        imgUpload.SetPropertyItem(oProp);

                        // works: Also tested writing other properties to this string, and other inputs work                   
                        oProp = CreatePropertyItem(0x8298, Address.Text + ", " + City.Text + ", " + State.Text + " " + ZipCode.Text);
                        imgUpload.SetPropertyItem(oProp);
                       
                        oProp = CreatePropertyItem(0x010E, WhatKindOfFun.Value);
                        imgUpload.SetPropertyItem(oProp);
       
                        imgUpload.Save(Server.MapPath("tmp\\process-"+sNewFile));
                        imgUpload.Dispose();
                       
                        // Create directories.
                        DateTime oDate = DateTime.Now;

                        this.CreateFTPDirectory("ftp://64.179.77.44/"+Convert.ToString(oDate.Year)+"/");
                        this.CreateFTPDirectory("ftp://64.179.77.44/"+Convert.ToString(oDate.Year)+"/"+Convert.ToString(oDate.Month)+"/");
                        this.CreateFTPDirectory("ftp://64.179.77.44/"+Convert.ToString(oDate.Year)+"/"+Convert.ToString(oDate.Month)+"/"+Convert.ToString(oDate.Day)+"/");
                       
                        // FTP file to Interchange.
                        FtpWebRequest oFTP = (FtpWebRequest)FtpWebRequest.Create("ftp://64.179.77.44/"+Convert.ToString(oDate.Year)+"/"+Convert.ToString(oDate.Month)+"/"+Convert.ToString(oDate.Day)+"/"+sNewFile);
                        oFTP.Method = WebRequestMethods.Ftp.UploadFile;
                        oFTP.Credentials = this.oCred;
                        oFTP.UsePassive = true;
                        oFTP.UseBinary = true;
                        oFTP.KeepAlive = false;
                       
                        FileStream oFile = File.OpenRead(Server.MapPath("tmp\\process-"+sNewFile));
                        byte[] oBuffer = new byte[oFile.Length];
                        oFile.Read(oBuffer, 0, oBuffer.Length);
                        oFile.Close();
                       
                        Stream oStream = oFTP.GetRequestStream();
                        oStream.Write(oBuffer, 0, oBuffer.Length);
                        oStream.Close();
                       
                    //    File.Delete(Server.MapPath("tmp\\upload-"+sNewFile));
                    //    File.Delete(Server.MapPath("tmp\\process-"+sNewFile));
                       
                        Response.Redirect("The site it goes to");
                    } catch {
                    }
                }

    Filed under: , ,
Page 1 of 1 (1 items)