Cached Data from Website to Word Doc
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!

