Cached Data from Website to Word Doc

Hello,
I am having an issue with cached data in a Word document that is getting setup by a web page, but it only has an issue on the web server. I have a word document report that is being triggered to open from a web page and it is auto populating based on cached data and a web service.

The code is very similar to the Benefits Registration Sample:http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odc_vsto2005_ta/html/OfficeVSTOBenefitsRegistration.asp

When I run the code locally, the cached data is populated correctly and the report generates fine. When I deploy it to the server, the cached data is coming up null. I have coded around the null and found that the document is running correctly and generating the report data correctly through the web page if I hard code the cache data when it is null. So the issue has to be some kind of difference in the data caching.

Are there settings on the server that must be set to allow the server to cache info in the word document?

Here is code from the HttpHandler where I cache the data:

public void ProcessRequest(HttpContext context)
{
// Get the user context, available only when users sign in.
string userName = context.User.Identity.Name;

if (userName == null || userName == string.Empty)
{
// Unauthorized request, only logged in users allowed.
throw new HttpException(401,
"You must login prior to requesting the Proposal Form.");
}

// Get the path to the Proposal form document.
string formPath = context.Request.PhysicalPath;

// Ensure the file exists.
if (!File.Exists(formPath))
{
throw new HttpException(404, "Word Form requested (" +
context.Request.FilePath + ") could not be found. Please" +
" check the document path and try again.");
}

// Disallow non-customized documents.
if (!ServerDocument.IsCustomized(formPath))
{
throw new HttpException(500, "Word Form requested (" +
context.Request.FilePath + ") is not a valid form." +
" Please have an administrator upload the form again.");
}

FileStream fs = null;
ServerDocument sd = null;

// Open a the file as a stream.
using (fs = new FileStream(formPath, FileMode.Open,
FileAccess.Read, FileShare.ReadWrite))
{
// Pass the filename & extension indicating the type of document.
sd = new ServerDocument(fs, Path.GetFileName(formPath));
}

// Get the object that will host the cached data items.
CachedDataHostItem hostItem = null;

if (sd.CachedData.HostItems["ProposalDocument.ThisDocument"] == null)
{
hostItem =
sd.CachedData.HostItems.Add("ProposalDocument.ThisDocument");
}
else
{
hostItem =
sd.CachedData.HostItems["ProposalDocument.ThisDocument"];
}

// Populate the Cached Data
string EstimateIDString = GetEstimateIDString(Path.GetFileName(formPath));
string ProposalIDString = GetProposalIDString(Path.GetFileName(formPath));

// Cache benefit data set in the document.
if (EstimateIDString != null)
{
CacheString(hostItem, "EstimateID", EstimateIDString);
}
else
{
throw new HttpException(500, "Could not load EstimateID for the form requested.");
}
// Cache Word data in the document.
if (ProposalIDString != null)
{
CacheString(hostItem, "PropID", ProposalIDString);
}
else
{
throw new HttpException(500, "Could not load ProposalID for the form requested.");
}

sd.Save();
// Write the document to the client HTTP stream.
WriteHttpResponse(context.Response, sd.Document);

fs.Close();
sd.Close();
}

Sample code from ThisDocument pulling in cached data:

#region Cached DataSets.

/// <summary>
/// Cached Data
/// </summary>
private string _EstimateID;
[Cached]
public string EstimateID
{
get { return _EstimateID; }
set { _EstimateID = value; }
}

private string _PropID;
[Cached]
public string PropID
{
get { return _PropID; }
set { _PropID = value; }
}

#endregion

public static string EstimateIDString;
private ProposalActionPane PropActionPane = new ProposalActionPane();
private void ThisDocument_Startup(object sender, System.EventArgs e)
{

PopulateProposal();
this.ActionsPane.Controls.Add(PropActionPane);
}

private void ThisDocument_Shutdown(object sender, System.EventArgs e)
{
}

private void PopulateProposal()
{
int DetailID = 0;
int ProposalID = 0;
EstimateIDString = "";
//<TESTING>
if (EstimateID == null)
{
MessageBox.Show("EstimateID = null!!");
DetailID = 4175;
ProposalID = 4175;
EstimateIDString = "4175";
}
else
{
MessageBox.Show("EstimateID = " + EstimateID);
DetailID = int.Parse(EstimateID);
ProposalID = int.Parse(EstimateID); //Uses EstimateID
EstimateIDString = EstimateID;
}
if (PropID == null)
{
MessageBox.Show("PropID = null!!");
}
else
{
MessageBox.Show("PropID = " + PropID);
}

//</TESTING>
string status = "";

Can anyone offer any help with what could be causing this issue?

Thanks!

[5327 byte] By [gbobg] at [2007-12-27]
# 1
Well, I ended up figuring this out on my own. It seems that IIS on the server behaves differently than my local webserver. IIS does not like httphandlers for file ententions that are known windows file extentions (.doc). Here is an article I found that describes it exactly:

http://codebetter.com/blogs/karlseguin/archive/2006/05/24/145397.aspx

"Why not to use HttpHandlers

The biggest and very significant drawback of

HttpHandlers is that they can only be used for extensions that are

mapped to ASP.NET in IIS. It might be great to create a file download

counter for your .zip files using an HttpHandler, but since IIS doesn't

go through ASP.NET to serve .zip files, it isn't going to work. One

solution is to map those extra extension to ASP.NET, but that might

have undesirable side effects and might not even be possible for you

(many developers don't have direct access to IIS). In this case, the

only solution is to create an ISAPI filter which is much more

difficult. IIS 7 promises to let us write ISAPI filters in .NET (or

extend HttpHandlers beyond the ASP.NET pipeline depending on how you

look at it), but that's still a ways away."

Anyway, I was able to put the code in the code-behind instead of in an httphandler, and now it seems to be getting the cached data.

Cheers,

Jeff

gbobg at 2007-9-3 > top of Msdn Tech,Visual Studio Tools for Office,Visual Studio Tools for Office...