Re: Can't find items in Attachments

  •  08-17-2009, 4:52 AM

    Re: Can't find items in Attachments

    Thanks Terry, another thing.. I have this function that resize images before it copies the image to my server;
    1. private void ItemPicture_FileUploaded(object sender, UploaderEventArgs args)  
    2.     {  
    3.         if (GetVisibleItemCount() >= 5)  
    4.             return;  
    5.   
    6.         using (System.IO.Stream stream = args.OpenStream())  
    7.         {  
    8.             ItemPictureAttachments.Upload(args.FileSize, args.FileName, ResizeFromStream(640, stream));  
    9.             // ItemPictureAttachments.Items.Add(args.FileSize, args.FileName, stream);  
    10.         }  
    11.     }  
    12.   
    13.     public Stream ResizeFromStream(int MaxSideSize, Stream Buffer)  
    14.     {  
    15.         int intNewWidth;  
    16.         int intNewHeight;  
    17.         System.Drawing.Image imgInput = System.Drawing.Image.FromStream(Buffer);  
    18.   
    19.         // GET IMAGE FORMAT  
    20.         ImageFormat fmtImageFormat = imgInput.RawFormat;  
    21.   
    22.         // GET ORIGINAL WIDTH AND HEIGHT  
    23.         int intOldWidth = imgInput.Width;  
    24.         int intOldHeight = imgInput.Height;  
    25.   
    26.         // IS LANDSCAPE OR PORTRAIT ??   
    27.         int intMaxSide;  
    28.   
    29.         if (intOldWidth >= intOldHeight)  
    30.         {  
    31.             intMaxSide = intOldWidth;  
    32.         }  
    33.         else  
    34.         {  
    35.             intMaxSide = intOldHeight;  
    36.         }  
    37.   
    38.   
    39.         if (intMaxSide > MaxSideSize)  
    40.         {  
    41.             // SET NEW WIDTH AND HEIGHT  
    42.             double dblCoef = MaxSideSize / (double)intMaxSide;  
    43.             intNewWidth = Convert.ToInt32(dblCoef * intOldWidth);  
    44.             intNewHeight = Convert.ToInt32(dblCoef * intOldHeight);  
    45.         }  
    46.         else  
    47.         {  
    48.             intNewWidth = intOldWidth;  
    49.             intNewHeight = intOldHeight;  
    50.         }  
    51.           
    52.         // CREATE NEW BITMAP  
    53.         Bitmap bmpResized = new Bitmap(imgInput, intNewWidth, intNewHeight);  
    54.   
    55.   
    56.         // SAVE BITMAP TO STREAM  
    57.         MemoryStream imgStream = new MemoryStream();  
    58.         bmpResized.Save(imgStream, imgInput.RawFormat);  
    59.   
    60.         // RELEASE RESOURCES  
    61.         imgInput.Dispose();  
    62.         bmpResized.Dispose();  
    63.         Buffer.Close();  
    64.   
    65.         return imgStream;  
    66.     }  
    But for some reason it return a file with 0 bytes and copies this empty file into my server. What am I missing?
     
    Thanks,
     
    - Ryan
View Complete Thread