Free Support Forum - aspose.com

System.IO.FileNotFoundException: Could not find file

I am trying to use the trial version of Aspose.words Net. As you can see I am very new to all this, but would appreciate your help. I have prepared a vb.net page in MS Visual Studio 2005. My code is listed below.

I know I am probably being silly - but would appreciate your help - Thank you

When I try to run the letter I get an error

Could not find file 'c:\windows\system32\inetsrv\polcomp.doc'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.IO.FileNotFoundException: Could not find file 'c:\windows\system32\inetsrv\polcomp.doc'.

Source Error:

Line 30:        Private Sub Button1_click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Line 31:       
Line 32:         Dim doc As Document = New Document("polcomp.doc")
Line 33:                 
Line 34:         Dim dataReader As IDataReader = Nothing

My code follows

<%@ Import Namespace= "System.Text.RegularExpressions" %>

<%@ Import Namespace= "Microsoft.VisualBasic" %>

<%@ Import Namespace= "System.Data" %>

<%@ Import Namespace= "Aspose.Words" %>

<script runat="server">

Private Sub Button1_click(ByVal sender As System.Object, ByVal e As System.EventArgs)

Dim doc As Document = New Document("polcomp.doc")

Dim dataReader As IDataReader = Nothing

Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("/fpdb/passliabcapture.mdb") & ";")

conn.Open()

Try

Dim cmd As New OleDbCommand("SELECT From Results UserID, BrokerName, Comment, Title, Initials, Surname, IDno, dob, diff, WkCode, HmNo, HmCode, WkNo, Cellno, txtEmail, IDno8, IDno9, IDno1, IDno5, IDno2, IDno6, D1, fin_area0, IDno3, IDno7, man, mod, [year], Colour, Reg_No, VRN, Engno, Engcap, fin_noseats, fin_liab, fin_pa, fin_fun, fin_brokfee, fin_ppa, fin_pliab, fin_fun1, fin_premium, fin_mnthpremium, SASRIA, fin_monthly0, fin_totalbrok, fin_mnthtotalbrok, fin_totalpremium, fin_totalmnthpremium, Cover, Plan, fin_Liablimit, Financed, financehouse, Financehousebrnch, Financeaccno, acc,Motoracc, stolen, Motostolen, fire, Motorfire, prosecution, ownedacc,fin_cashprice, fin_extras, fin_amount, fin_track, fin_disc, fin_band, Fin_Band1, fin_dot, fin_dot1, fin_totaldisc, COB, excess1, excess2, excess3, excess4, excess5, excess6", conn)

dataReader = cmd.ExecuteReader()

doc.MailMerge.Execute(dataReader)

Finally

If Not dataReader Is Nothing Then

dataReader.Close()

End If

If Not conn Is Nothing Then

conn.Close()

End If

End Try

doc.Save("polcomp1.doc", SaveFormat.Doc, SaveType.OpenInBrowser, Response)

End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

<title>Untitled Page</title>

</head>

<body>

<form id="form1" runat="server">

<div>

<asp:button id="Button1" onclick="Button1_click" runat="server" text="Print schedule"></asp:button>

</div>

</form>

</body>

</html>

Hi

Thanks for your inquiry.

1. Are you sure that file “c:\windows\system32\inetsrv\polcomp.doc” exists?

2. If your document is located in your web app folder then you can use Server.MapPath(“polcomp.doc”).

Let me know if you have any other questions.

Best regards.

Thank you so much for the quick reply - Answer 2 sorted the problem (mappath).

I will go ahead and purchase a full copy.

Once again thanks for the great response