Gemini Community Support Site

This Gemini community support site can be used to find solutions to product issues. You can log in using Open Id, Google Profile and even Facebook. Feel free to ask a question or browse FAQs and documentation. Product tour videos are also available along with how-to videos demonstrating key Gemini capabilities.




Web Services - Creating attachments

web-app

I recently started playing around with attching a file to new issue and cant seem to get it to work. 

Can anyone help.  Below is sample code from Countersoft's sample application modified to attach a file on issue creation.

private void btnCreateIssueClick(object sender, System.EventArgs e)

{

IssueEN data=new IssueEN();

IssueComponentEN[] iceComps = new IssueComponentEN[1];

iceComps[0] = new IssueComponentEN();

FileEN[] files = new FileEN[1];

files[0] = new FileEN();

iceComps[0].ComponentID = 1;

data.Components = iceComps;

data.FixedInVersion=0;

data.IssueLongDesc=txtDesc.Text;

data.IssuePriority=1;

data.IssueResolution=1;

data.IssueStatus=1;

data.IssueSummary=txtTitle.Text;

data.IssueType=1;

data.IssueSeverity = 1;

data.ReportedBy=1;

data.RiskLevel=1;

data.Visibility = 1;

data.VisibilityMemberType = GeminiConstant.SecurityMemberType.GlobalGroup;

data.ReportedByUsername = "test@test.com";

data.ProjectID = (int)numProjectID.Value;

System.IO.FileInfo attachment = new System.IO.FileInfo("c:\test.txt");

System.IO.FileStream fs = attachment.OpenRead();

byte[] bytes = new byte[fs.Length];

fs.Read(bytes, 0, (int)fs.Length);

fs.Close();

files[0].FileData = bytes;

files[0].FileName = "testatt";

files[0].ProjectID = (int)numProjectID.Value;

data.Attachments = files;

try

{

// Note that this might throw a security exception.

data.IssueID=msmProxyManager.IssueServices.CreateIssue(data);

BindGrid();

}

catch(Exception ex)

{

MessageBox.Show(this,ex.Message);

}

}

EWH
· 1
EWH
Replies (4)
helpful
0
not helpful

You need to set the content length:

files[0].ContentLength = bytes.Length;


Mark Wing
· 9108
Mark Wing
helpful
0
not helpful

Thank you for the reply but Im still getting an error:

files[0].FileData = bytes;

files[0].ContentLength = bytes.Length;

files[0].FileName = "test.txt";

files[0].ProjectID = (int)numProjectID.Value;

Does anyone have a code example to do this?


EWH
· 1
EWH
helpful
0
not helpful

The code works for me. What is the error?


Mark Wing
· 9108
Mark Wing
helpful
0
not helpful

Its solved for some reason CommentID requires something other than 0 even though it stores 0 in the DB if not on a comment.  Thank you for the help.


EWH
· 1
EWH