I created a web application for uploading files and associated metadata. When I test the solution on my laptop, it works without a problem (file gets uploaded and metadata is saved). When I try the deployed solution on the server, I get file not found error: 'Could not find file 'c:\windows\system32\inetsrv\award.txt'. Through my application, I'm trying to upload a file from my laptop, so I'm not sure what is going on. Can someone tell me how to fix this?
if (fileUpload.HasFile)
{
using (SPSite site = new SPSite(SPContext.Current.Web.Url))
{
using (SPWeb web = site.OpenWeb())
{
using (FileStream fs = (new FileInfo(fileUpload.PostedFile.FileName)).OpenRead())
{
SPList list = web.Lists["Awards"];
//Add the initial metadata. We will do an update for all lookup table values, as they need to be done after the record is created.
Hashtable ht = new Hashtable();
ht.Add("wfRecipientRank", ddRanks.SelectedValue);
ht.Add("wfRecipientName", txtRecipientName.Text);
ht.Add("APFT", rbPassedApft.SelectedValue);
ht.Add("HeightWeight", rbMeetHtWt.SelectedValue);
ht.Add("Posthumous", rbPosthumous.SelectedValue);
SPFile file = list.RootFolder.Files.Add(fileUpload.FileName, fs, ht, false);
SPListItem item = file.Item;
//Get the lookup field values
SPList lookupList = web.Lists["AwardType"];
int awardTypeId = GetItemId(ddAwardTypes.SelectedValue, lookupList);
SPFieldLookupValue awardTypeLookupValue = new SPFieldLookupValue();
if (awardTypeId > 0)
awardTypeLookupValue = new SPFieldLookupValue(awardTypeId, ddAwardTypes.SelectedValue);
lookupList = web.Lists["AwardReason"];
int awardReasonId = GetItemId(ddAwardReasons.SelectedValue, lookupList);
SPFieldLookupValue awardReasonLookupValue = new SPFieldLookupValue();
if (awardReasonId > 0)
awardReasonLookupValue = new SPFieldLookupValue(awardReasonId, ddAwardReasons.SelectedValue);
lookupList = web.Lists["Organization"];
MilitaryUnit organizationSelected = null;
SPFieldLookupValue organizationLookupValue = new SPFieldLookupValue();
if (Session["OrganizationSelected"] != null)
{
organizationSelected = (MilitaryUnit)Session["OrganizationSelected"];
int organizationId = GetItemId(organizationSelected.uic, lookupList);
if (organizationId > 0)
organizationLookupValue = new SPFieldLookupValue(organizationId, txtOrganization.Value);
}
item["Organization"] = organizationLookupValue;
item["AwardType"] = awardTypeLookupValue;
item["AwardReason"] = awardReasonLookupValue;
item.Update();
}
}
}
}