Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

Automatizacija Worda u HTML

[es] :: .NET :: Automatizacija Worda u HTML

[ Pregleda: 2018 | Odgovora: 1 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

sivan347
.NET Programer
Beograd

Član broj: 84406
Poruke: 101
*.adsl-4.sezampro.yu.



Profil

icon Automatizacija Worda u HTML13.11.2007. u 21:41 - pre 166 meseci
Radio sam konvertovanje Word-a u HTML tako sto klijent preko FileUpload kontrole radi upload word dokumenta na server u jedan folder gde ga ja automatski otvaram i snimam u drugi folder kao HTML fajl koji kasnije ucitavam u IFRAME. To sve radi ali moj problem je sto kad odradi sve word se ne zatvara tj. proces winword.exe ostaje kao aktivan proces tako da kad god urade upload svaki put se kreira winword.exe proces i nakraju dolazi do pucanja worda. Da li neko zna kako da eliminisem taj proces. Evo kod koji to radi na click event:
if (fuDoc.HasFile)
{

try
{

//To check the file extension if it is word document or something else
string strFileName = fuDoc.FileName;
string detail = "";
string[] strSep = fuDoc.FileName.Split('.');
int arrLength = strSep.Length - 1;
string strExt = strSep[arrLength].ToString().ToUpper();

object FileName = strPathToUpload + "\\" + fuDoc.FileName;
object FileToSave;
if (strExt.ToUpper().Equals("DOC") || strExt.ToUpper().Equals("DOCX"))
{
DataAccess da = new DataAccess();
//Save the uploaded file to the folder
fuDoc.SaveAs(strPathToUpload + "\\" + fuDoc.FileName);
objWord = new ApplicationClass();
//open the file internally in word. In the method all the parameters should be passed by object reference
objWord.Documents.Open(ref FileName, ref readOnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref isVisible, ref missing, ref missing, ref missing, ref missing, ref missing);
//Do the background activity
objWord.Visible = false;
oDoc = objWord.ActiveDocument;
detail = oDoc.Content.Text.Replace("'"," ");
string query = "EXEC insEntries " + txtRank.Text + ",N'" + txtTitle.Text.Replace("'", "''") + "',N'" + txtBrief.Text.Replace("'", "''") + "',N'" + videoPath + "'," + lbTopics.SelectedValue + ",N'" + detail + "'";
DataTable dt = da.GetDataTable(query);
if (dt.Rows.Count > 0)
strPathToConvert = strPathToConvert + "\\" + dt.Rows[0].ItemArray[0].ToString();
DirectoryInfo dir = new DirectoryInfo(strPathToConvert);
if (!dir.Exists)
dir.Create();
//Map-path to the folder where html to be saved
FileToSave = strPathToConvert + "\\" + fuDoc.FileName + ".htm";
oDoc.SaveAs(ref FileToSave, ref fltDocFormat, 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);
lbErr.Text = "Succesful entry !!";
txtBrief.Text = "";
txtRank.Text = "";
txtTitle.Text = "";
}
else
{
lbErr.Text = "Invalid word file selected !!";
}

}
catch (Exception ex)
{

lbErr.Text = ex.Message;
}
finally
{
//Close/quit word
if (oDoc != null)
{
oDoc.Close(ref missing, ref missing, ref missing);
oDoc = null;
}
if (objWord != null)
{
objWord.Quit(ref missing, ref missing, ref missing);
objWord = null;
}

}
}
 
Odgovor na temu

sivan347
.NET Programer
Beograd

Član broj: 84406
Poruke: 101
*.fiberop.matgnet.com.



Profil

icon Re: Automatizacija Worda u HTML14.11.2007. u 08:31 - pre 166 meseci
Evo sam cu sebi dati odgovor:
System.Runtime.InteropServices.Marshal.ReleaseComObject(objWord);
treba postaviti u finally.
 
Odgovor na temu

[es] :: .NET :: Automatizacija Worda u HTML

[ Pregleda: 2018 | Odgovora: 1 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.