This is a weird one. For years, a bit of code to upload files to SharePoint has been working on my dev machine. It just stopped working the other day! No exceptions are being thrown, but there is a weird response string coming back in the WebResponse. Here's the code:
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(absoluteUrl);
if (this._authenticationService == null)
{
// Windows authentication
request.Credentials = _credentials;
}
else
{
// Forms authentication
request.CookieContainer = this._authenticationService.CookieContainer;
}
request.Method = "PUT";
byte[] buffer = new byte[4 * 1024];
using (Stream stream = request.GetRequestStream())
{
using (FileStream fs = File.OpenRead(localFilePath))
{
for (int i = fs.Read(buffer, 0, buffer.Length); i > 0; i = fs.Read(buffer, 0, buffer.Length))
{
stream.Write(buffer, 0, i);
}
}
}
WebResponse response = request.GetResponse();
response.Close();
If I add some code to check the actual response like this:
StreamReader responseReader = new StreamReader(response.GetResponseStream());
responseReader.ReadToEnd();
The output from that code is this, a seemingly uncompiled aspx page!!!!:
<%@ Assembly Name=\"Microsoft.SharePoint.ApplicationPages, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c\"%> <%@ Page Language=\"C#\" Inherits=\"Microsoft.SharePoint.ApplicationPages.ErrorPage\" MasterPageFile=\"~/_layouts/simple.master\" %> <%@ Import Namespace=\"Microsoft.SharePoint.ApplicationPages\" %> <%@ Register Tagprefix=\"SharePoint\" Namespace=\"Microsoft.SharePoint.WebControls\" Assembly=\"Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c\" %> <%@ Register Tagprefix=\"Utilities\" Namespace=\"Microsoft.SharePoint.Utilities\" Assembly=\"Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c\" %> <%@ Import Namespace=\"Microsoft.SharePoint\" %>\r\n<%@ Register Tagprefix=\"SharePoint\" Namespace=\"Microsoft.SharePoint.WebControls\" Assembly=\"Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c\" %> <%@ Register Tagprefix=\"Utilities\" Namespace=\"Microsoft.SharePoint.U tilities\" Assembly=\"Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c\" %> <%@ Import Namespace=\"Microsoft.SharePoint\" %>\r\n\r\n\t\" EncodeMethod='HtmlEncode'/>\r\n\r\n\r\n\t\" EncodeMethod='HtmlEncode'/>\r\n\r\n\r\n\t\r\n\t\r\n\r\n\r\n \r\n\t\r\n\t\r\n\t \r\n\t\t \r\n\t \r\n\t
\r\n\t\t<%\r\n\t\t\tif (IsAdministrationSite)\r\n\t\t\t{ %>\r\n\t\t\t\t\" EncodeMethod=\"NoEncode\" runat=\"server\"> \" EncodeMethod='HtmlEncode'/> \r\n\t\t<% } else { %>\r\n\t\t\t\t\" EncodeMethod=\"NoEncode\" runat=\"server\"
\" EncodeMethod='HtmlEncode'/> \r\n\t\t<% } %>\r\n\t\t\r\n\t\r\n\t\r\n \r\n\r\n\t var gearPage = document.getElementById('GearPage');\r\n\t if(null != gearPage)\r\n\t {\r\n\t\t gearPage.parentNode.removeChild(gearPage);\r\n\t\t document.title = \"' EncodeMethod='HtmlEncode'/>\";\r\n\t }\r\n\r\n
What's happened?!?!
Ok, I caved and uninstalled and reinstalled WSS with SP2, and the latest cumulative update package, and reconnected to the existing farm and that's sorted this problem!