|
I need to convert html div content to ms word in below code C# Microsoft.office.interop.word.htmldivision add invalid parameter error occurred.
StringBuilder objStrBuilder = new StringBuilder();
objStrBuilder.Append("<table>");
objStrBuilder.Append("<tr>");
objStrBuilder.Append("<td>");
objStrBuilder.Append("HP");
objStrBuilder.Append("<\td>");
objStrBuilder.Append("<td>");
objStrBuilder.Append("HP computer");
objStrBuilder.Append("<\td");
objStrBuilder.Append("<\tr>");
objStrBuilder.Append("<tr>");
objStrBuilder.Append("<td>");
objStrBuilder.Append("HP Labs");
objStrBuilder.Append("<\td>");
objStrBuilder.Append("<td>");
objStrBuilder.Append("HP computer Joy");
objStrBuilder.Append("<\td");
objStrBuilder.Append("<\tr>");
objStrBuilder.Append("<\table>");
dic.InnerHtml = objStrBuilder.ToString();
Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();
word = null;
try
{
object missing = System.Reflection.Missing.Value;
word = new Microsoft.Office.Interop.Word.Application();
object template = @"D:\\DS_Template11.dotx";
word.Documents.Add(Template: ref template);
word.Visible = true;
object readOnly = false;
object filename = "http://localhost:60510/tr/Default.aspx";
Microsoft.Office.Interop.Word.Document document = word.Documents.Open(ref filename, ref missing, ref readOnly, 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);
// Microsoft.Office.Interop.Word.Section wordSectio = document.Sections;
foreach (Microsoft.Office.Interop.Word.Section wordSectin in document.Sections)
{
foreach (Microsoft.Office.Interop.Word.HTMLDivision wordSection in document.HTMLDivisions)
{
String text = "this is footer";
//Get the footer range and add the footer details.
Microsoft.Office.Interop.Word.Section s1=document.Sections.Add(); ;
Microsoft.Office.Interop.Word.Paragraph p1 = document.Paragraphs.Add();
Microsoft.Office.Interop.Word.Range R1 = p1.Range;
Microsoft.Office.Interop.Word.HTMLDivision h1= R1.HTMLDivisions.Add();
h1.
R1.ContentControls=dic.
R1.HTMLDivisions = dic.InnerHtml;
//Microsoft.Office.Interop.Word.Range footerRange = wordSection.Footers[Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range;
Microsoft.Office.Interop.Word.HTMLDivision para = wordSection.HTMLDivisions.Add(dic.InnerHtml);
Range.Fields.Add(Range, Microsoft.Office.Interop.Word.WdFieldType.wdFieldHTMLActiveX);
modified 13-Feb-15 6:16am.
|
|
|
|
|
Is this a question, a proud boast, or just some spam?
|
|
|
|
|
Dude this is query sure if know the answer then reply plz
|
|
|
|
|
You still have not asked a question. Please edit your original post and add some proper detail about what problem you are trying to solve, and what errors or problems you are facing.
|
|
|
|
|
I need to convert an HTML Div which is made dynamically and run the page ,entire content of page should be converted into word document on client machine only
|
|
|
|
|
Did you understand what I mean by the statement: Please edit your original post and add some proper detail about what problem you are trying to solve, and what errors or problems you are facing.? Telling us what you want, is not an explanation of a problem.
Also looking at your code you are running some C# code using Microsoft.Office.Interop.Word . Is this running at the server or the client? If the latter then I do not think it will work.
|
|
|
|
|
how do I insert a word, pdf and text to sql database and view the files in gridview using vb.asp
|
|
|
|
|
The same way you would with another technology. Be sure to use a parameterized statement.
|
|
|
|
|
Because those documents can be large and contain images, you should consider storing them in a folder and just store the path string in the db, especially if your db budget is low.
|
|
|
|
|
i am reading pdf files saved on MSSQL server in form of byte array and trying to display in iframe. I am facing the problem. the first file I had opened is opening again and again even deleting cookies and clear up the temp folder. the code I am using is as below:
Dim RID As String
RID = Request.QueryString("RPTID")
Dim rptProp() As String = RPT.getReport(CInt(RID)) 'Reading file attributes from database using a function writtent in an other class.
If rptProp(6) <> "" Then
Filename = rptProp(7)
Me.Filename = Filename
Me.Extension = Mid(rptProp(7), rptProp(7).IndexOf("."c) + 2, rptProp(7).Length)
Dim doc() As Byte = Nothing
doc = RPT.getRepDoc(CInt(RID)) 'Reading exact file bytes stored in MS SQL database using a function getRepDoc(Document_ID as integer) written in another class designed for data communication between web forms and database.
If doc IsNot Nothing Then
If Extension = "pdf" Then
Dim base64String As String = Convert.ToBase64String(doc, 0, doc.Length)
Dim pdfIFrameSrc = "data:Application/pdf;base64,{0}" + base64String
' set the src attribute
Me.iFRM.ResolveUrl(pdfIFrameSrc) ' iFRM is an ID of iFrame
End If
End If
modified 12-Feb-15 5:17am.
|
|
|
|
|
I used the VS2013 Community Edition and created a new MVC Project, and one with the hero accent.
I customized it to my liking, to use as my new website and wanted to start adding web pages to it.
So I created a Controller AppsController.cs and a folder in Views called /Views/Apps
Then I created 4 view pages in Apps, one called MVC.cshtml
I get the page not found, or resource cannot be found when I type in
http://localhost:18525/Apps/MVC[^]
I think my understanding is correct, in which the controller finds the view file. But how does MVC know about the controller, to find the view file. Or perhaps I'm way off track here, and it's a routing issue.
I have no clue here on this
All the help on this says right click, add controller, but I don't get those choices in VS2013 or VS2012. Nor the Add View, I choose Add -> EmptyPage Razor V3.0
I'm not going to post any code since I'm sure what to post.
|
|
|
|
|
I created a new project, and put my stuff back in it to retain the design
Then I ran the NuGet, and updated all my packages
Figured out that I can't or don't know how to add a folder inside home view for /home/Apps
So I just added a new controller called Apps and a view /View/Apps for now.
The right Click works now add Controller, add view
And I have MVC version 5 now.
This is way different than web forms, but I can see the payoff in the future.
|
|
|
|
|
Hello, since you've not provided any code and/or any other background I am unable to guide you any further. Anyways, that link you provided is not applicable to my IIS and thus I am unable to examine the problem.
Anyhow, the problem is that beginners do get into this problem. I have an article[^], that you would find helpfull to you and you would find it easy to understand the ASP.NET MVC pattern, by using that example.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
Well thanks for the offer for help. Really wasn't any code to post, because I didn't know what to post.
This is frustrating learning this, on top of CSS 3 and HTML5, but so far so good.
Here's what I have now. Keep in mind that I just started learning MVC this Monday, 3 days ago. So I thought why not update my website first, and see how it goes.
http://www.redcopper.net[^]
|
|
|
|
|
You should've posted the methods in which you're creating the application, the controllers and their representative views etc.
Anyhow, it doesn't take much time to understand the ASP.NET MVC pattern, you just need to first make yourself clear with the concept of the MVC pattern, and the code patterns in ASP.NET. Rest of the things would be learnt on the way. Mostly, 404 errors are generated when there is no file in your website to display in your browser, or none of the routings meet the URL.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
There must be a bond in which the controller is recognized, so it picks up the view.
Plus I found out the views must be in the folder that the controller makes.
Was sort of looking for the file in which this bond is made, unless it's a automatic search in the whole view folder structure.
|
|
|
|
|
Did you even read that article[^] that I tried to ask you to read? That has atleast the basic concepts of the ASP.NET MVC framework. You would get how and which pages are used in the MVC as the Views, how Controller acts and all other underlying things.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
I did read your article.
I understand how it works
I had trouble with Visual Studio 2013, in which I wasn't able to get the same right clicks and menu choices as show in your examples.
I made the mistake of opening the project as a website, and not a project, so VS2013 didn't know it was a MVC App.
Now I open it as a project, and all is fine.
|
|
|
|
|
Hello Everyone,
Please i would appreciate any urgent answer/help on the above subject. Actually, am about to start working on a project that involves developing a website where registered employees (on a remote desktop application) can come and view their basic information.
I understand i need to make some API calls that would fetch the data from the remote desktop database and render it on html for the users.
Please can anyone provide me with useful tip/tutorial/guide/reference on how to start?
Thanks in advance.
IsoftTech
modified 11-Feb-15 10:16am.
|
|
|
|
|
There are multiple ways of doing this, but the first thing as I have already said in almost all of my answers to such question is the "connection string". You're required to have the connection string, which is composed of the server's address (or atleast the name to which you would connect it to), the name of the database, and the required credentials for connection.
Once that has been taken care of you can then use the SQL commands to perform different actions on the database, which would include extraction, insertion or updation etc. Please go through this article[^] of mine to get a few more understanding of the concept.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
Thanks Afzaal for your response. I went through your article and observed that it was about connecting to a local database as oppose connecting to remote database via a Web API.
IsoftTech
|
|
|
|
|
Sorry for any problem you had to face, but the article had a section the connection string section. That depicts the usage of a connection string to connection to remove databases. If you go to the connectionstrings website then you would see how to connect to a remote database, remaining code is similar, the only thing to worry about is the connection string. Did you try that out?
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
Server Error in '/' Application.
Operation must use an updateable query.
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.Data.OleDb.OleDbException: Operation must use an updateable query.
Source Error:
Line 26: cmd.Parameters.AddWithValue("@ecat", cat);
Line 27: cn.Open();
Line 28: int i= cmd.ExecuteNonQuery();
Line 29: cn.Close();
Line 30: return i;
Source File: c:\domains\Paystole.com\wwwroot\App_Code\Dal\DEduCat.cs Line: 28
Stack Trace:
[OleDbException (0x80004005): Operation must use an updateable query.]
System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr) +1081596
System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) +247
System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) +194
System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) +58
System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) +167
System.Data.OleDb.OleDbCommand.ExecuteNonQuery() +113
DEduCat.DInsert(String cat) in c:\domains\Paystole.com\wwwroot\App_Code\Dal\DEduCat.cs:28
BEduCat.BInsert() in c:\domains\Paystole.com\wwwroot\App_Code\Bal\BEduCat.cs:33
Admin_Education.bntSave_Click(Object sender, EventArgs e) in c:\domains\Paystole.com\wwwroot\Admin\Education.aspx.cs:80
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +118
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +112
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1025
|
|
|
|
|
|
My ASP.NE Test Page is as follows:
TestPage.aspx:
<%@ Page Language="VB" MasterPageFile="~/Site.master" AutoEventWireup="false" CodeFile="TestPage.aspx.vb" Inherits="TestPage" title="Test Page"%>
<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>
<asp:content id="Content1" contentplaceholderid="MainContent" runat="Server">
<asp:toolkitscriptmanager id="ToolkitScriptManager1" runat="server">
Test Page
<asp:updatepanel id="UpdatePanel1" runat="server" updatemode="Conditional">
<contenttemplate>
<asp:textbox id="txtAddress" runat="server" height="16px" width="200px"><input id="btnSelect" type="button" value="Select" onclick="AddTextBox();" />
<asp:button id="btnSave" runat="server" text="Save">
<script type="text/javascript">
function GetDynamicTextBox(textboxValue) {
//alert('Debug 01' + textboxValue);
var width = document.getElementById("ctl00_MainContent_txtAddress").style.width;
return "<input name = 'Text1' type='text' value = '" + textboxValue + "' style='width:" + width + "';/>"
//alert('Debug 02' + width);
}
function AddTextBox() {
var thisAdd = document.getElementById("ctl00_MainContent_txtAddress");
if (thisAdd.value == 0) return false;
var div = document.createElement('DIV');
div.innerHTML = GetDynamicTextBox(document.getElementById("ctl00_MainContent_txtAddress").value);
document.getElementById("targetDiv").appendChild(div);
document.getElementById("ctl00_MainContent_txtAddress").value = '';
}
function RecreateDynamicTextboxes() {
var txtValues = eval('<%=TxtValues%>');
alert('Debug 02: ' + txtValues);
if (txtValues != null) {
var html = "";
for (var i = 0; i < txtValues.length; i++) {
html += "" + GetDynamicTextBox(txtValues[i]) + " ";
}
document.getElementById("targetDiv").innerHTML = html;
}
}
function pageLoad() {
RecreateDynamicTextboxes();
}
</script>
Now Code Behind (TestPage.aspx.vb) is as follows:
Imports System.Data.SqlClient
Imports System.Web.Script.Serialization
Partial Class TestPage
Inherits System.Web.UI.Page
Protected TxtValues As String
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
Protected Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
Dim serializer As New JavaScriptSerializer()
Dim textboxValues As String() = Request.Form.GetValues("Text1")
Me.TxtValues = serializer.Serialize(textboxValues)
End Sub
End Class
If I remove "UpdatePanel" and then run it, enter some text in the textbox, click "select" and do this for a few lines and finally click "Save", the PostBack returns the text lines entered.
But when I add "UpdatePanel" back in then it fails on line:
var txtValues = eval('<%=TxtValues%>'); of javascript "function RecreateDynamicTextboxes()" i.e. TxtValues contains nothing after PostBack.
Can I request if someone can suggest ways to make this work please?
mbmirza
|
|
|
|