Ejemplo n.º 1
0
        /// <summary>
        /// Save Image into data base/folder
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="buffer">image Byte array</param>
        /// <param name="imageID">image ID for the file</param>
        /// <param name="imageName">name of the i,age</param>
        /// <param name="isSaveInDB">is want to save into the data base</param>
        /// <returns></returns>
        public static int SaveImage(Ctx ctx, byte[] buffer, int imageID, string imageName, bool isSaveInDB)
        {
            MImage mimg = new MImage(ctx, imageID, null);

            mimg.ByteArray   = buffer;
            mimg.ImageFormat = imageName.Substring(imageName.LastIndexOf('.'));
            mimg.SetName(imageName);
            if (isSaveInDB)
            {
                mimg.SetBinaryData(buffer);
                //mimg.SetImageURL(string.Empty);
            }
            else
            {
                // if user uncheck the save in db checkbox
                mimg.SetBinaryData(null);
            }
            mimg.SetImageURL("Images");
            //else
            //{
            //    mimg.SetImageURL("Images");//Image Saved in File System so instead of byteArray image Url will be set
            //    mimg.SetBinaryData(new byte[0]);
            //}
            if (!mimg.Save())
            {
                return(0);
            }
            return(mimg.Get_ID());
        }