Here is what I do for a CSV with excel but I don't know what you would need to do to encode it properly for word.
Dim dv2 As System.Data.DataView = CType(Me.SqlDataSource2.Select(DataSourceSelectArg uments.Empty), System.Data.DataView)
Dim dr2 As System.Data.DataRow = dv.Table.Rows(0)
If Not Directory.Exists("C:\Reports\" + bString) Then
Directory.CreateDirectory("C:\Reports\" + bString)
End If
If IsNumeric(DropDownList1.Text) Then
sw = New StreamWriter("c:\reports\" + bString + "\" + DropDownList3.Text + "_" + DropDownList1.Text + "_Inventory_Report.csv", False, Encoding.ASCII)
'sw = New StreamWriter(home + "\Desktop\" + DropDownList3.Text + "_" + DropDownList1.Text + "_Inventory_Report.csv", False, Encoding.ASCII)
Else
sw = New StreamWriter("c:\reports\" + bString + "\" + DropDownList3.Text + "_Complete_Inventory_Report.csv", False, Encoding.ASCII)
'sw = New StreamWriter(home + "\Desktop\" + DropDownList3.Text + "_Complete_Inventory_Report.csv", False, Encoding.ASCII)
End If
'StreamWriter sw = new StreamWriter("c:\\" + locationBox.Text + "_Inventory_Report.csv", false, Encoding.ASCII);
' int init = 0;
' /*do
' {
'sw.Write("TEST" + ", ")
If DropDownList3.Text.Contains("Non Reporting") Then
sw.Write("Row ID" + ", ")
'sw.Write("MAC Address" + ", ")
sw.Write("Barcode" + ", ")
'sw.Write("Domain" + ", ")
sw.Write("TagID" + ", ")
sw.Write("Description" + ", ")
sw.Write("Location" + ", ")
sw.Write("Serial" + ", ")
sw.Write("Unitcode" + ", ")
sw.Write("Purchase Date" + ", ")
sw.Write("Purchase Order" + ", ")
sw.Write("Purchase Price" + ", ")
sw.Write("UTSA User" + ", ")
sw.Write(System.Environment.NewLine)
Else
sw.Write("Computer Name" + ", ")
'sw.Write("MAC Address" + ", ")
sw.Write("Desription" + ", ")
'sw.Write("Domain" + ", ")
sw.Write("Serial" + ", ")
sw.Write("Processor" + ", ")
sw.Write("Operating System" + ", ")
sw.Write("Service Pack" + ", ")
sw.Write("Free Space on C:" + ", ")
sw.Write("RAM Amount" + ", ")
sw.Write("Last User" + ", ")
sw.Write("Manufacturer" + ", ")
sw.Write("Last Date Logged" + ", ")
sw.Write("OU" + ", ")
sw.Write(System.Environment.NewLine)
End If
If IsNumeric(DropDownList1.Text) Then
If DropDownList3.Text.Contains("Non Reporting") Then
For Each drz As DataRow In dv2.Table.Rows
If drz(6).Contains(DropDownList1.Text) Then
If drz(3).ToString.Contains("CPU") Then
sw.Write(drz(0).ToString + "," + drz(1).ToString + "," + drz(2).ToString + "," + drz(3).ToString + "," + drz(4).ToString + "," + drz(5).ToString + "," + drz(6).ToString + "," + drz(7).ToString + "," + drz(8).ToString + "," + drz(9).ToString + "," + drz(10).ToString)
sw.Write(System.Environment.NewLine)
End If
End If
Next
End If
Hope it helps. -Mike
This was also from a web application so the web.config contains my connection strings and then the aspx page contains my query:
<asp

qlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:CoehdITDataConnectionString2 %>"
ProviderName="<%$ ConnectionStrings:CoehdITDataConnectionString2.Pro viderName %>"
SelectCommand="SELECT * from [inventory] as ci left join ComputersData as cd on cd.pc_serial = ci.serial where cd.pc_serial IS NULL">
</asp

qlDataSource>