Microsoft.Office.Interop.Word.Document myDoc = wordApp.Documents.Add(ref missing, ref missing,
ref missing, ref missing);
ファイルストリームに入れたいときに呼び出すにはどうすればよいですか?
//DOC download
private void DownloadDoc()
{
object fileName = LabelFirstNameFromDb.Text + "_" + LabelLastNameFromDb.Text + "_" +
DateTime.Now.ToString("yyyy-MM-dd") + "." + DropDownListDownload.SelectedItem.Text;
var db = new KnowItCvdbEntities();
SPWeb theSite = SPControl.GetContextWeb(Context);
SPUser theUser = theSite.CurrentUser;
string strUserName = theUser.LoginName;
var theEmpl = (from p in db.EMPLOYEES
where p.username == strUserName
select p).FirstOrDefault();
if (theEmpl != null)
{
object missing = Missing.Value;
object start1 = 0;
var wordApp = new ApplicationClass();
Microsoft.Office.Interop.Word.Document myDoc = wordApp.Documents.Add(ref missing, ref missing,
ref missing, ref missing);
Range rng = myDoc.Range(ref start1, ref missing);
try
{
object fileStream = new FileStream(Server.MapPath("~/Upload/") + fileName,
FileMode.Create);
myDoc.SaveAs(ref fileStream, ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing,
ref missing, ref missing, ref missing);
wordApp.Visible = true;
const char newLine = (char)11;
//CERTIFICATES
string certificate = string.Empty;
var lbCertificate = new Label();
foreach (var vCert in BulletedListCertificates.Items)
{
certificate += " - " + vCert + newLine;
}
lbCertificate.Text = newLine + LabelCertificates.Text + newLine + certificate;
rng.InsertAfter(lbCertificate.Text);
}
catch (Exception)
{
throw;
}
finally
{
myDoc.Save();
if (RadioButtonListLanguage.SelectedItem.Text == "Swedish")
{
RepeaterAssignments.Controls.Clear();
SetCustomizedCvAssignmentsSkillSwe();
}
else if (RadioButtonListLanguage.SelectedItem.Text == "English")
{
RepeaterAssignments.Controls.Clear();
SetCustomizedCvAssignmentsSkillEng();
}
}
Response.ContentType = "Application/msword";
Response.AppendHeader("Content-Disposition", "attachment; filename=" + fileName);
Response.TransmitFile(Server.MapPath("~/Upload/") + fileName);
Response.End();
}
}