Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello !

I have a question about uploading a file by XML . I have this part of code , on the server side (Bugzilla) that i can't touch . I just can use the URL in my client side code.

C#
public static void UploadPhoto(Photo chosenPhoto)
       {
           string uriParameters = string.Format("?mimeType={0}&description={1}&bugId={2}&submitterId={3}&fileName={4}",
           chosenPhoto.MimeType, chosenPhoto.Description, chosenPhoto.BugId, chosenPhoto.SubmitterId, chosenPhoto.FileName);
           string randomToken = "&randomToken=" + new Random().Next().ToString();
           bugzillaUrl = new Uri(uriBase + uriParameters + randomToken, UriKind.Absolute);
           photo = new byte[(int)chosenPhoto.PhotoStream.Length];
           chosenPhoto.PhotoStream.Read(photo, 0, (int)chosenPhoto.PhotoStream.Length);
           uploadAttachment();
       }


So, in my client side, I want to add a photo, so a picture, and I have to enter all the parameter of the URL .

C#
protected void ButtonUpload_Click(object sender, EventArgs e)
        {
            if (TextBoxDescription.Text != "")
            {
                if (FileUploadAttach.HasFile)
                {
                    try
                    {
                        //Add Attachement
                        string paramMimeType = FileUploadAttach.PostedFile.ContentType;
                        string paramDescription = TextBoxDescription.Text;
                        string paramBugId = Request.QueryString.Get("bugId");
                        string paramSubmitterId = Request.Cookies["UserSettings"]["Userid"];
                        string paramFileName = FileUploadAttach.PostedFile.FileName;


                        WebClient wc = new WebClient();

                        resultUpload = ("http://192.168.0.18/buggateway/SetAttachment.aspx?mimeType=" + paramMimeType + "&description=" + paramDescription + "&bugId=" + paramBugId + "&submitterId=" + paramSubmitterId + "&fileName=" + paramFileName);
                        wc.UploadFile(resultUpload, paramFileName);
                        TextBoxDescription.Text = "";
                        PanelAllAttachment.Controls.Clear();
                        LoadBugsAttachments();
                    }
                    catch
                    {
                        txtOutput.InnerHtml = "Error saving <b>" +
                        FileUploadAttach.PostedFile.FileName + "</b><br>" + e.ToString();
                    }
                }
            }
            else
            {
                Response.Write("Description missing");
            }


        }


So my question is :

The file is uploading , but the file is empty when I retrieve it .
How can I pass the byte array from my client side , to the server side ? Should I use HTTP something ? Or Photo stream ... ?

Can someone help me ?


Thank you very much .
Posted
Updated 24-Oct-11 5:40am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900