Need help converting this VBS to C#

mypicturefaded

Newcomer
Joined
Jun 22, 2009
Messages
3
I have this VBScript that I am trying to convert to C# and I am a little stuck on what I should be doing.

Code:
Set Request = CreateObject("MSXML2.DOMDocument.4.0")
Request.async = false
with Request.appendChild(Request.createElement("fnApiRequest"))
  .setAttribute "cmd", "QueryLibrary"
end with
with Request.documentElement.appendChild(Request.createElement("library"))
  .setAttribute "name", "name of database"
  .setAttribute "user", "username"
  .setAttribute "password", "userpassword"
end with
with Request.documentElement.appendChild(Request.createElement("query"))
    .text = "myquery"
end with

' send request
Set HTTP = CreateObject("WinHTTP.WinHTTPRequest.5.1")
HTTP.setTimeouts 0, 30000, 30000, 600000
HTTP.SetAutoLogonPolicy 0
HTTP.Open "POST", "thewebsite", false

HTTP.Send Request

' receive response
if HTTP.status = 200 then
  Set Response = CreateObject("MSXML2.DOMDocument.4.0")
  Response.async = false
   if Response.LoadXML(HTTP.responseText) then
    Response.save "QueryResponse.xml"
    if ucase(Response.documentElement.getAttribute("status")) = "OK" then
      MsgBox Replace(Response.xml, "><", ">" & vbCr & "<"), , "OK Response"
      'MsgBox Nodes(1).xml, , "OK Response"
    else
      MsgBox Replace(Response.xml, "><", ">" & vbCr & "<"), , "ERROR Response"
      Err.Raise CLng(Response.selectSingleNode("//number").text), _
                Response.selectSingleNode("//source").text, _
                Response.selectSingleNode("//description").text
    end if
  else
    MsgBox HTTP.responseText, , "Invalid web service response: " & HTTP.responseText
  end if
else
  MsgBox HTTP.responseText, , "Response error: " & HTTP.statusText
end if

Here is the code that I have so far. I just need a step in the right direction. I don't know how I would all those parameters.

Code:
  string strNewValue; 
            string strResponse; 

            // Create the request obj 
            HttpWebRequest req = (HttpWebRequest) WebRequest.Create("http://someur.com/page.aspx"); 

            // Set values for the request back 
            req.Method = "POST"; 
            req.ContentType = "application/x-www-form-urlencoded";
            req.Credentials = new NetworkCredential("username", "password");
            strNewValue = "fnApiRequest" + "&param1=cmd&parm2=QueryLibrary";
            req.ContentLength = strNewValue.Length; 

            // Write the request 
            StreamWriter stOut = new StreamWriter (req.GetRequestStream(), System.Text.Encoding.ASCII); 
            stOut.Write(strNewValue); 
            stOut.Close(); 

            // Do the request to get the response 
            StreamReader stIn = new StreamReader(req.GetResponse().GetResponseStream()); 
            strResponse = stIn.ReadToEnd(); 
            stIn.Close();
 
Last edited:
I am trying to get some XML info from a library. I need to pull out an item ID.
If you went to the page, you would have to hit a tab to select the library, and then do a search for the document. Then you would see what you are looking for. I want to get the XML from that.
 
Back
Top