I want to be able to POST some values to an external web site's ASP page and then programmatically read the results. The external page has no query string paramaters so I can't just create the url and read the page instead I need to create some web requests and deal with that object. This is how I did it, basically a mash up of what I found on the web but I believe more concise and clear.
//set our data
ASCIIEncoding encoding = new ASCIIEncoding();
string postData = "firstname=" + fname.Text;
postData += ("&lastname=" + lname.Text);
//compose the submission
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://somepage.asp");
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = postData.Length;
// Post to the form.
StreamWriter swRequestWriter = new StreamWriter(request.GetRequestStream());
swRequestWriter.Write(postData);
swRequestWriter.Close();
//get the response
HttpWebResponse hwrWebResponse = (HttpWebResponse)request.GetResponse();
// Read the response
StreamReader srResponseReader = new
StreamReader(hwrWebResponse.GetResponseStream());
string strResponseData = srResponseReader.ReadToEnd();
srResponseReader.Close();
// Display the response on my page
Response.Write(strResponseData);
Now what I plan to do is screen scrape the result page and get the data I need. Ah regular expressions, I hate those. Stay tuned for that post in the next couple of days...
Monday, July 28, 2008
Thursday, July 24, 2008
Creating a SharePoint stsadm command prompt on the dektop
Create a quick shortcut to the stsadm command prompt for your SharePoint server.
http://blogs.msdn.com/scicoria/archive/2008/07/24/creating-a-wss-moss-command-prompt-on-the-desktop.aspx
http://blogs.msdn.com/scicoria/archive/2008/07/24/creating-a-wss-moss-command-prompt-on-the-desktop.aspx
Finding the SQL behind a Crystal Report
I need to find the SQL that generated a Crystal Report. All I had was the report definition file and Visual Studio 2008.
After creating a new DSN (Windows XP users click here for instructions) I opened up the report in VS and clicked the Crystal Reports menu at the top. Then Database -> Show SQL Query. A wizard will popup, click the Back button, choose the newly created DSN for your database and then click Next. Login with your credentials and click Finish. Whalla (spelling??) I now see the previously hidden SQL.
After creating a new DSN (Windows XP users click here for instructions) I opened up the report in VS and clicked the Crystal Reports menu at the top. Then Database -> Show SQL Query. A wizard will popup, click the Back button, choose the newly created DSN for your database and then click Next. Login with your credentials and click Finish. Whalla (spelling??) I now see the previously hidden SQL.
InfoPath Percentage Symbol Field
This applies to InfoPath 2007 as well.
That's just wrong:
Note Microsoft Office InfoPath 2003 does not add percent symbols to numbers that are formatted as percentages. To add a percent symbol to a control's label, click where you want the percent symbol to appear, and then type %.
http://office.microsoft.com/en-us/infopath/HP010938331033.aspx
That's just wrong:
Note Microsoft Office InfoPath 2003 does not add percent symbols to numbers that are formatted as percentages. To add a percent symbol to a control's label, click where you want the percent symbol to appear, and then type %.
http://office.microsoft.com/en-us/infopath/HP010938331033.aspx
Wednesday, July 23, 2008
Programmatically remove digital signatures from Excel document
Here is some sample code to remove all digital signatures from an Excel workbook. This can be run from a Windows app or Console app. I'm going to try to make it work within a SharePoint document library event handler. That should be interesting. Basically the idea is to have a document library that has a bunch of documents that are digitally signed and then every month get reset by removing all the digital signatures. Hope this runs in the event handler.
Microsoft.Office.Interop.Excel.Application eApp = null; Microsoft.Office.Interop.Excel.Workbook wb = null;
//gets our workbook
eApp = new Microsoft.Office.Interop.Excel.Application();
wb = eApp.Workbooks.Open(textBox1.Text, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
//makes it visible and activates the workbook
//eApp.Visible = true;
//wb.Activate();
//get signatures
Microsoft.Office.Core.SignatureSet sigs = wb.Signatures;
//remove all the signatures
foreach (Microsoft.Office.Core.Signature sig in sigs)
{ sig.Delete(); }
//save and close the form
wb.Save();
wb.Close(Type.Missing, Type.Missing, Type.Missing);
wb = null;
eApp = null;
Microsoft.Office.Interop.Excel.Application eApp = null; Microsoft.Office.Interop.Excel.Workbook wb = null;
//gets our workbook
eApp = new Microsoft.Office.Interop.Excel.Application();
wb = eApp.Workbooks.Open(textBox1.Text, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
//makes it visible and activates the workbook
//eApp.Visible = true;
//wb.Activate();
//get signatures
Microsoft.Office.Core.SignatureSet sigs = wb.Signatures;
//remove all the signatures
foreach (Microsoft.Office.Core.Signature sig in sigs)
{ sig.Delete(); }
//save and close the form
wb.Save();
wb.Close(Type.Missing, Type.Missing, Type.Missing);
wb = null;
eApp = null;
Tuesday, July 22, 2008
Sample valid credit card numbers
I often need to test my forms with credit card information, so here are some valid numbers for each type of card, although I doubt they will work in reality but they pass the Luhn Algorithm for my testing.
Visa
4111 1111 1111 1111
MasterCard
5500 0000 0000 0004
American Express
3400 0000 0000 009
Discover
6011 0000 0000 0004
Visa
4111 1111 1111 1111
MasterCard
5500 0000 0000 0004
American Express
3400 0000 0000 009
Discover
6011 0000 0000 0004
EmailSubmitConnection :How to add custom email to an InfoPath email data connection EmailSubmitConnection
EmailSubmitConnection : Often times I need to add some more information to an email that is sent from InfoPath besides just a view of the form. Sometimes I want to add fields and such to the body of the email but just end up adding the fields to the subject line since there is no way without writing code to include fields in the introduction field of the email. I hope with Office 14 they make this possible without writing code, but for right now let's see how to do it.
First, you need to create a data connection (EmailSubmitConnection) that sends an email to someone within the InfoPath data connections. This data connection needs to be created so we can reference it in our code.
Second get into the code behind of the form, I'm using C# for InfoPath 2007 so those with InfoPath 2003 may have to figure this out for themselves but hopefully this gives them some clues.
Within, probably a button click event, I get a reference to the email data connection. The "email connection" is the name of the data connection I created in the first step.
EmailSubmitConnection emailDataConnection = (EmailSubmitConnection)this.DataConnections["email connection"];
//add your custom message to the introduction, say hello to yourself
XPathNavigator xnDoc = this.MainDataSource.CreateNavigator();
XPathNavigator fullName = xnDoc.SelectSingleNode("my:myFields/my:txtFullName", this.NamespaceManager);
emailDataConnection .Introduction = "My custom introduction with some fields. Hello " + fullName.Value;
//submit the data connection which sends the email
emailDataConnection .Execute();
As you can see, just get a reference to the data connection (EmailSubmitConnection), set the Introduction property and execute. This can also be accomplished for the FileSubmitConnection and WebServiceConnection objects, so you can write code to execute these connections and set some custom properties before making the submit. Hope this helps someone.
First, you need to create a data connection (EmailSubmitConnection) that sends an email to someone within the InfoPath data connections. This data connection needs to be created so we can reference it in our code.
Second get into the code behind of the form, I'm using C# for InfoPath 2007 so those with InfoPath 2003 may have to figure this out for themselves but hopefully this gives them some clues.
Within, probably a button click event, I get a reference to the email data connection. The "email connection" is the name of the data connection I created in the first step.
EmailSubmitConnection emailDataConnection = (EmailSubmitConnection)this.DataConnections["email connection"];
//add your custom message to the introduction, say hello to yourself
XPathNavigator xnDoc = this.MainDataSource.CreateNavigator();
XPathNavigator fullName = xnDoc.SelectSingleNode("my:myFields/my:txtFullName", this.NamespaceManager);
emailDataConnection .Introduction = "My custom introduction with some fields. Hello " + fullName.Value;
//submit the data connection which sends the email
emailDataConnection .Execute();
As you can see, just get a reference to the data connection (EmailSubmitConnection), set the Introduction property and execute. This can also be accomplished for the FileSubmitConnection and WebServiceConnection objects, so you can write code to execute these connections and set some custom properties before making the submit. Hope this helps someone.
Subscribe to:
Posts (Atom)