コード例 #1
0
        protected void btnAdd_Click(object sender, System.EventArgs e)
        {
            // Get Posted File
            HttpPostedFile theFile = upAttachment.PostedFile;


            // Check if file was actually uploaded
            if (theFile == null)
            {
                return;
            }

            // Convert Posted File to Byte Array
            int fileSize = theFile.ContentLength;

            byte[]           fileBytes = new byte[fileSize];
            System.IO.Stream myStream  = theFile.InputStream;
            myStream.Read(fileBytes, 0, fileSize);

            // Get file name
            string fileName = Path.GetFileName(theFile.FileName);

            // Create new Issue Attachment
            IssueAttachment newAttachment = new IssueAttachment(IssueId, Page.User.Identity.Name, fileName, theFile.ContentType, fileBytes);

            newAttachment.Save();
            BindAttachments();
        }
コード例 #2
0
        protected void SaveAttachement(int issueId, string userName, byte[] fileBytes)
        {
            // Get file name
            string fileName    = issueId.ToString();
            string contentType = "JPG";

            // Create new Issue Attachment
            IssueAttachment newAttachment = new IssueAttachment(issueId, userName, fileName, contentType, fileBytes);

            newAttachment.Save();
        }