I have a console application and a web application.the web application call the console application and the console application create an instance of a MSWORD .it is working fine in visual studio.But when I host the web app in IIS and try localhost:222 it don't work.
here is my code
web app code
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim info = New System.Diagnostics.ProcessStartInfo()
info.FileName="F:\ConsoleApplication1\bin\Debug\ConsoleApplication1.exe"
info.Arguments = TextBox1.Text & " " & TextBox2.Text
info.UseShellExecute = True
Dim process = New System.Diagnostics.Process()
process.StartInfo = info
process.Start()
process.WaitForExit()
End Sub
And the console app code is
Public Sub Main(args As String())
' CREATE AN OBJECT FOR WORD
Dim objWord As Object
objWord = CreateObject("Word.Application")
objWord.visible = True
End Sub
Anybody know what is the problem.
Related
I'm trying to export my crystal report to pdf but keep getting the "failed to open a connection" error. It seems as if the error is happening at the CR.Export line. I've tried everything but don't know how to fix it. FYI, it's working on my development server, but when I copy it to the production server, I get the error. So it's very hard to pin point where it's occurring.
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
Try
InitializeComponent()
strPermitNo = Session("RecordID")
SpWithViewer(strPermitNo)
CrystalReportViewer2.DataBind()
Catch er As Exception
LogError(er.ToString, "PageInit-PrintPermit1.aspx")
Exit Try
Finally
End Try
End Sub
`
Protected Sub btnExport_Click(sender As Object, e As EventArgs) Handles btnExport.Click
strPermitNo = Session("RecordID")
Try
Dim CrExportOptions As ExportOptions
Dim CrDiskFileDestinationOptions As New DiskFileDestinationOptions()
Dim CrFormatTypeOptions As New PdfRtfWordFormatOptions()
CrDiskFileDestinationOptions.DiskFileName = "\\idsfmsrvr\wwwroot\FWPDFs\" & strPermitNo & ".pdf"
strAttachment = "\\idsfmsrvr\wwwroot\FWPDFs\" & strPermitNo & ".pdf"
Session("Attachment") = strAttachment
CrExportOptions = CR.ExportOptions
If True Then
CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile
CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat
CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions
CrExportOptions.FormatOptions = CrFormatTypeOptions
End If
CR.Export()
EmailPermitToApplicant()
File.Delete(strAttachment)
lblMsg.Text = "Permit has been emailed to applicant."
lblMsg.Visible = True
Catch er As Exception
LogError(er.ToString, "btnExport()-PrintPermit1.aspx")
Exit Try
Finally
connFTS.Close()
End Try`
Just a step:
Open a report first, follow this link
Export it whatever you want.
Take note: you can hide the form if you don't want to display the report.
Good Luck!
I have run into a problem in my asp.net and vb.net programming. I have made a website which connects to a database to authenticate users. I have made another page which my windows form application uses to authenticate users so the program does not have to connect directly to the MySql Database as this is insecure.
So far, the code for my asp.net page is:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
If Request.QueryString.Keys(0) = "key" And Request.QueryString.Keys(1) = "getapikeyv1" And Request.QueryString.Keys(2) = "authapienc2" Then
Dim key As String = Request.QueryString.Get("key")
If key = "dua9r3rqpK{WPDWp9r93af03r8yqrEPIF{A}W~DW)D08q3raewdawdug9q8wdyaw9wq" Then
returnLabel.Text = "XYeJay4XVh6amvf1kJ34Y6y6hR0sSokP9oJFsi0Mxl4QB0T86W0iac9o2nRfCmFmsONq6sPz+rdX+/NqFk3inHRGnwnqf0IsQXE/M/SvnvY="
Else
returnLabel.Text = "invk"
End If
Else
returnLabel.Text = "invalidrequest"
End If
End If
End Sub
The default value for 'returnLabel' is INVALIDREQUEST. My api keys defined above are working fine so are not needed to be considered here. However, when I use the following code to communicate with the webpage, it always returns with returnLabel's value as 'INVALIDREQUEST'. Even if I put the returnLabel.Text = "1233" at the beginning of the Me.Load sub, the page still returns INVALIDREQUEST when I communicate with it through my program!
I use this code to request:
Try
Dim APIRequest As New WebClient
APIRequest.QueryString.Add("key", r9j0wqfha0fh0wf0.DecryptString128Bit(APIKey5, dVadaihwdq93ra0w0))
APIRequest.QueryString.Add("getapikeyv1", "")
APIRequest.QueryString.Add("authapienc2", "")
Dim ako39rqwfa As String = APIRequest.DownloadString(EncryptionPageUrl)
MsgBox(ako39rqwfa)
Dim m As Match = Regex.Match(ako39rqwfa, "<span id=""returnLabel"">.*?</span>")
APIKey00 = m.Value.Replace("<span id=""returnLabel"">", "").Replace("</span>", "")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
As you can see, the WebClient I use is fine but the Me.Load sub in the webpage is not responding the request made by the program...
Is there any way I can make the webpage respond to the WebClient.DownloadString() function?
Thanks,
Rodit
(ps. c# or vb code would be appreciated)
Change your asp.net page to check the query string like this, not sure if you can assume they are in a certain order:
If Request.QueryString.Get("key") isnot nothing And
Request.QueryString.Get("getapikeyv1") isnot nothing And
Request.QueryString.Get("authapienc2") isnot nothing Then
When I open a page from another web application on same domain I am trying to read the cookie that was created on the original page, But it I cant read the cookie. If I move that page in to the same web application then it works, but thats not what I want.
[Domain: MyCompany.mobi]
[WebApp A] - create cookie and launch page
Protected Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
Dim aCookie As New HttpCookie("TestCookie")
aCookie.Value = "Hello World"
aCookie.Expires = DateTime.Now.AddDays(1)
Response.Cookies.Add(aCookie)
Dim script = "window.open('http://MyCompany.mobi/webappB/default.aspx?id=TestCookie')"
'open page in WebsiteB
ScriptManager.RegisterStartupScript(Me, Me.GetType, "OpenPage", script, True)
End Sub
[Domain: MyCompany.mobi]
[WebApp B] - read the cookie and display in label
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim id As String = ""
If Request.QueryString("id") IsNot Nothing Then id = Request.QueryString("id").ToString
If Request.Cookies(id) IsNot Nothing Then
Dim aCookie As HttpCookie = Request.Cookies(id)
Label1.Text = aCookie.Name & " : " & aCookie.Value
Else
Label1.Text = "Cannot read cookie"
End If
End Sub
Cookies are associated with domain names; not the physical servers that are pointed to by DNS.
For security reasons, you cannot read cookies from a different domain name.
You need to pass the information in the URL.
Background: I have a winform application written in VB.NET that uses a WebService to send out different invitations to users based on the marketing company they select to take different interviews. The winform app is pulling string values from a variety of textboxes, listboxes, and dropdownlists to create some XML and push it to a web service called AcompServiceClient
Questions:
Is there a wizard or 3rd party application that will export winform data to webform asp.net or should I build an aspx page from scratch w/ the same namespaces for all the controls as the winform app?
Which files do I need to transport or setup to make this work besides the AcompServiceClient web service and the code-behind vb? (look at screenshot of the Project Files)
Do i have to copy over any parts of the app.config file and adapt it to the web.config file?
I was thinking:
I can start by copying the Acomp_Invitation_Form.vb to the AComp_Invitation_Web_App.aspx.vb code behind page.
Add existing webservice off the webserver
Manually re-add formatting, text boxes, list boxes, and drop down lists on the front end aspx page using the same names / id's
Here's a screenshot of the WinForm App:
Here's a screenshot of the Project Files:
Here's my code on Acomp_Invitation_Form.vb:
Imports TestClient.aCompService
Imports System.Text
Public Class Form1
Private proxy As New AcompServiceClient
Private Sub stuff()
Dim splitContractingBundle() As String
splitContractingBundle = Split(cb2.SelectedItem, "|")
Dim splitMarketingCompany() As String
splitMarketingCompany = Split(cb3.SelectedItem, "|")
Dim strDate As String = System.DateTime.Now.ToString
Dim strOpData As String = String.Format("{0}~{1}~{2}~{3}~{4}~{5}~{6}~{7}~{8}~{9}~{10}",
Trim(splitMarketingCompany(0)), txtFirstName.Text, "", txtLastName.Text,
txtEmail.Text, txtEmail.Text, "1", strDate,
"Pending", "1/1/1900", Trim(splitContractingBundle(0)))
Dim int1 As Boolean = proxy.AddContractOpportunity(strOpData, "test", "test")
txtEmail.Text = ""
txtFirstName.Text = ""
txtLastName.Text = ""
lbCarriers.Items.Clear()
cb2.Items.Clear()
cb3.Items.Clear()
cb2.SelectedItem = ""
cb3.SelectedText = ""
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'TODO Add code to validate that all selections that are reaquired are met.
'ccemail and the additional message are not required
Dim firstname As String = txtFirstName.Text
Dim lastname As String = txtLastName.Text
Dim ccEmail As String = txtccEmail.Text
Dim sb As New StringBuilder
sb.AppendLine("<?xml version=""1.0"" encoding=""utf-8""?>")
sb.AppendLine("<root>")
sb.AppendLine("<MarketingCompany>")
sb.AppendLine("<MarketingCompanyName>")
''Get Marketing Company Short Name
Dim splitMC As String() = Split(cb3.SelectedItem, "|")
Dim MCShort As String = Trim(splitMC(0))
sb.AppendLine(String.Format("<MCNAme>{0}</MCNAme>", MCShort))
'sb.AppendLine(String.Format("<MCNAme>{0}</MCNAme>", My.Settings.MarketingCompanyShortName))
sb.AppendLine(String.Format("<ccEmail>{0}</ccEmail>", txtccEmail.Text))
sb.AppendLine(String.Format("<emailMessage>{0}</emailMessage>", txtMessage.Text))
sb.AppendLine(String.Format("<MarketerName>{0}</MarketerName>", txtMarketerName.Text))
sb.AppendLine("<agent>")
sb.AppendLine(String.Format("<FirstName>{0}</FirstName>", txtFirstName.Text))
sb.AppendLine(String.Format("<LastName>{0}</LastName>", txtLastName.Text))
sb.AppendLine(String.Format("<Email>{0}</Email>", txtEmail.Text))
sb.AppendLine("<CRMGuid>123456</CRMGuid>")
Dim spltBundles() As String
For Each item In cb2.SelectedItems
If Trim(item) <> "" Then
spltBundles = Split(item, "|")
sb.AppendLine("<ContractingOpportunity>")
sb.AppendLine(String.Format("<Carrier>{0}</Carrier>", Trim(spltBundles(0))))
sb.AppendLine(String.Format("<ContractingOpportunityName>{0}</ContractingOpportunityName>", Trim(spltBundles(1))))
sb.AppendLine("</ContractingOpportunity>")
End If
Next
sb.AppendLine("</agent>")
sb.AppendLine("</MarketingCompanyName>")
sb.AppendLine(" </MarketingCompany>")
sb.AppendLine(" </root>")
Dim xmlStr = sb.ToString
Dim int1 As Boolean = proxy.AddContractOpportunity(xmlStr.ToString, "test", "test")
MsgBox("Made It")
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
GetCarriers()
GetMarketingCompanies()
End Sub
Private Sub GetCarriers()
Try
Dim ac1 As Array
ac1 = proxy.GetCarrierNames("test", "test")
For Each item In ac1
lbCarriers.Items.Add(String.Format("{0} | {1} | {2}", item.CarrierID, item.CarrierNameLong, item.CarrierNameShort))
Next
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub GetMarketingCompanies()
Try
Dim ac1 As Array
ac1 = proxy.GetMarketingCompanyNames("test", "test")
For Each item In ac1
cb3.Items.Add(String.Format("{0} | {1}", item.MarketingCompanyShort, item.MarketingCompanyName))
Next
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub lbCarriers_LostFocus(sender As Object, e As System.EventArgs) Handles lbCarriers.LostFocus
Dim splt() As String
Dim ac1 As Array
cb2.Items.Clear()
For Each item In lbCarriers.SelectedItems
splt = Split(item, "|")
ac1 = proxy.GetContractingBundles("test", "test", Trim(splt(0)))
For Each Pitem In ac1
cb2.Items.Add(Trim(splt(2)) & " | " & Pitem.FormBundleName)
Next
Next
End Sub
End Class
Be very careful of the easy way. While ASP.NET Web Forms might look similar to Windows Forms (controls hooked up to events), the underlying mechanism is very very different. If you have not done so already I recommend you read up on how HTTP works and the life cycle of an ASP.NET page.
Yes, the way you want to do it is the way I have done this many times.
Just copy the methods from your code behind and paste them into the code behind of your asp.net page. Some of your methods are not compatible because they are not supported in asp.net but you will find that our real quick when you build the project.
Create your web page with the controls having exactly the same name as the ones in the winform. When you build, all you have to do is fix your errors and you are on your way.
It looks like you are hooked up to some service so of course you will need to reference that.
Yeah, that's the general idea. I'd pay special attention to any concerns related to using AcompServiceClient in a stateless web environment. It's hard to say whether you have to rethink how you're using that or not without knowing anything about what it is, how it works or how it's consumed.
It doesn't look like you're doing anything else that relies on running in a stateful environment. You're just pulling string values from a variety of textboxes to create some XML and push it to a service. All of that should port over smoothly. You might want to look at adding some client side validation rules, but other than that it looks straight forward.
You'll want to change how you're populating your DropDownList. Those work a little different between win and web forms. It wants to be bound to a datasource in webforms.
I have a asp.net c# web application with contains reports in remote processing mode. I am using the report-viewer control to render the reports. When I run the application in debug mode, I'm able to view my reports however when I publish the application to a different server I get this error message:
The request failed with HTTP status 401: Unauthorized.
My report server is on a different server than the location of my published web application. I have added new role assignment to my report server and also added to my web.config but the error persists. I think I am missing something in my aspx page for reportviewer.
Any input would be appreciated.
I'm assuming you already have set the server in your codebehind such as this
reportviewer.ServerReport.ReportServerUrl = "http://{server_ip}/reportserver";
or via the properties of the report viewer control. Make sure you change {server_ip} to the actual for the report server.
Other such problems I've seen in the past have to do with access for individual reports. Since this is cross-server, you'll need a proxy user set to view the reports.
Here are 2 examples from MSDN:
Example 1
Example 2
Yes! use Page_Load & Page_Init in this way
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
ReportViewer1.Visible = True
Dim strReportsFolder As String = ConfigurationManager.AppSettings("ReportsFolder")
Dim reportName As String = "report1"
ReportViewer1.ServerReport.ReportPath = strReportsFolder + reportName
End Sub
Protected Sub Page_PreInit(ByVal sender As Object, ByVal e As EventArgs)
PopulateReport(ReportViewer1, "")
End Sub
Public Shared Sub PopulateReport(ByVal rptViewer As ReportViewer, ByVal reportName As String)
Dim strReportServer As String = ConfigurationManager.AppSettings("ReportServer")
Dim strUserName As String = ConfigurationManager.AppSettings("Username")
Dim strPassword As String = ConfigurationManager.AppSettings("Password")
Dim strDomain As String = ConfigurationManager.AppSettings("Domain")
rptViewer.ServerReport.ReportServerUrl = New Uri(strReportServer)
rptViewer.ServerReport.ReportServerCredentials = New ReportViewerCredentials(strUserName, strPassword)
End Sub