Question : Upload a file to SharePoint 2007 with C#.NET

I grabbed the code below from a MSDN site (http://msdn.microsoft.com/en-us/library/dd902097(office.12).aspx).  The purpose of it is to upload a file from my local machine to our corporate SharePoint 2007 site.  All of the uploads fail saying "ERROR: Access to the path 'C:\Test file.txt' is denied."

Does anyone know why I'm getting that error?
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
<asp:FileUpload ID="fileUpload" runat="server" Width="350px" />
                    <br />
                    <asp:Button ID="btnUpload" runat="server" OnClick="btnUpload_Click" Text="Upload File" />
                    <br />
                    <asp:Label ID="lblFileUpload" runat="server"></asp:Label>









protected void btnUpload_Click(object sender, EventArgs e)
        {
            string sharePointServer = ConfigurationManager.AppSettings["SharePointServer"].ToString();
            string uploadedFilePath = @"C:\\";
            string sharePointListPath = "http://" + sharePointServer + "InfoWorld/IT/ITTech/eForm%20Document%20Attachments";

            if (fileUpload.HasFile)
                try
                {
                    fileUpload.SaveAs(
                        uploadedFilePath + fileUpload.FileName);

                    lblFileUpload.Text = "File name: " +
                         fileUpload.PostedFile.FileName + "<br />" +
                         fileUpload.PostedFile.ContentLength + " bytes<br />" +
                         "Content type: " +
                         fileUpload.PostedFile.ContentType;

                    UploadFileToSharePoint(
                        uploadedFilePath + fileUpload.FileName,
                        sharePointListPath + fileUpload.FileName);
                }
                catch (Exception ex)
                {
                    lblFileUpload.Text = "ERROR: " + ex.Message.ToString();
                }
            else
            {
                lblFileUpload.Text = "You have not specified a file.";
            }
        }

        protected void UploadFileToSharePoint(string UploadedFilePath,
            string SharePointPath)
        {
            WebResponse response = null;

            try
            {
                // Create a PUT Web request to upload the file.
                WebRequest request = WebRequest.Create(SharePointPath);

                request.Credentials = CredentialCache.DefaultCredentials;
                request.Method = "PUT";

                // Allocate a 1 KB buffer to transfer the file contents.
                // You can adjust the buffer size as needed, depending on
                // the number and size of files being uploaded.
                byte[] buffer = new byte[4096];// 4 mb file limit.

                // Write the contents of the local file to the
                // request stream.
                using (Stream stream = request.GetRequestStream())
                using (FileStream fsWorkbook = File.Open(UploadedFilePath,
                    FileMode.Open, FileAccess.Read))
                {
                    int i = fsWorkbook.Read(buffer, 0, buffer.Length);

                    while (i > 0)
                    {
                        stream.Write(buffer, 0, i);
                        i = fsWorkbook.Read(buffer, 0, buffer.Length);
                    }
                }

                // Make the PUT request.
                response = request.GetResponse();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                response.Close();
            }
        }

Answer : Upload a file to SharePoint 2007 with C#.NET

This is XenApp, not XenServer so none of that will help :)

You should only need these using the WI

Application requests - TCP XML 80, 8080 or 443 (configurable)
Access to Applications Virtualized on the Server - ICA-TCP 1494, 2598 (Session Reliability)

Random Solutions  
 
programming4us programming4us