Profiles.Edit.Utilities.DataIO.SaveImage C# (CSharp) Méthode

SaveImage() public méthode

public SaveImage ( long subjectID, byte image, XmlDocument PropertyListXML ) : bool
subjectID long
image byte
PropertyListXML System.Xml.XmlDocument
Résultat bool
        public bool SaveImage(long subjectID, byte[] image, XmlDocument PropertyListXML)
        {
            ActivityLog(PropertyListXML, subjectID);
            SessionManagement sm = new SessionManagement();
            string connstr = ConfigurationManager.ConnectionStrings["ProfilesDB"].ConnectionString;

            image = this.ResizeImageFile(image, 150);

            SqlConnection dbconnection = new SqlConnection(connstr);

            SqlCommand comm = new SqlCommand();
            try
            {
                dbconnection.Open();
                comm.Connection = dbconnection;
                comm.CommandType = CommandType.Text;

                //Save this chestnut for when we edit
                using (SqlCommand cmd = new SqlCommand("exec [Profile.Data].[Person.AddPhoto] @Personid,@Photo", dbconnection))
                {
                    // Replace 8000, below, with the correct size of the field
                    cmd.Parameters.Add("@Personid", SqlDbType.Int).Value = GetPersonID(subjectID);
                    cmd.Parameters.Add("@Photo", SqlDbType.VarBinary).Value = image;
                    cmd.ExecuteNonQuery();
                    cmd.Connection.Close();
                }

                comm.Connection.Close();

                if (dbconnection.State != ConnectionState.Closed)
                    dbconnection.Close();
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return true;
        }

Usage Example

        protected void ProcessUpload(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
        {
            System.IO.Stream      stream;
            Edit.Utilities.DataIO data = new Profiles.Edit.Utilities.DataIO();
            stream = AsyncFileUpload1.PostedFile.InputStream;


            byte[] imageBytes = new byte[AsyncFileUpload1.PostedFile.InputStream.Length + 1];
            AsyncFileUpload1.PostedFile.InputStream.Read(imageBytes, 0, imageBytes.Length);

            data.SaveImage(this.SubjectID, imageBytes, this.PropertyListXML);
            base.GetSubjectProfile();
            this.PropertyListXML = propdata.GetPropertyList(this.BaseData, base.PresentationXML, this.PredicateURI, false, true, false);
            this.DrawProfilesModule();

            InitLinks();
            pnlUpload.Visible = false;
            upnlEditSection.Update();
        }
All Usage Examples Of Profiles.Edit.Utilities.DataIO::SaveImage