Resume uploading and description updating in profile in c#

Forum for users and developers of Bullhorn's Webservices API suite

Moderators: StaffingSupport, s.emmons, BullhornSupport

Post Reply
jitender
User
Posts: 18
Joined: Tue Mar 01, 2011 3:48 am

Resume uploading and description updating in profile in c#

Post by jitender » Wed Jul 13, 2011 11:49 am

Hi,

I want to upload resume but not getting how. I saw posts mentioning to use https://www.bullhornstaffing.com/Bullho ... Resume.cfm but in the code, path to file is mentioned static. How do we get that using file upload control. Is any code available in c# parsing resume and then updating description field.

Please help!!!!!!!!!

Thanks,
Jitender

apsmith
Site Admin
Posts: 2051
Joined: Wed Dec 31, 1969 8:00 pm

Re: Resume uploading and description updating in profile in c#

Post by apsmith » Wed Jul 20, 2011 9:06 am

Jitender,

That code will not upload a file, it will merely parse the file and return the contents as structured XML.

To upload a file, you should use this page (test page): http://www.bullhornstaffing.com/bullhor ... leTest.cfm

This page is a mockup in HTML of how to use our attach file API.
Andrew Smith
Director, Technical Operations
Developer Forum Admin

jitender
User
Posts: 18
Joined: Tue Mar 01, 2011 3:48 am

Re: Resume uploading and description updating in profile in c#

Post by jitender » Wed Jul 20, 2011 9:54 am

Hello apsmith,

Thanks for the reply. I tried following code but it didn't attached a file to files section of userid . For testing, I have added a static userid. In most of the posts, I saw a static resume file added to the userFile variable. As application is going to attach resume uploaded by user, static value can't work. Please review my code and correct where I am wrong.

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://www.bullhornstaffing.com/Bullho ... chfile.cfm");

string apiKey = Globals.apiKey;
string privateLabelID = Globals.PrivateLabelID;

string urlEncodedAPIKey = HttpUtility.UrlEncode(Globals.encryptedLegacyAPIKey);
string postURLData = "privateLabelID=" + privateLabelID +
"&encryptedAPIKey=" + urlEncodedAPIKey +
"&userID=80277"+
"&userFile=" + userfile.PostedFile.FileName+
"updateResumeOverview=True";
byte[] postDataBytes = Encoding.UTF8.GetBytes(postURLData);


request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = postDataBytes.Length;

Stream requestStream = request.GetRequestStream();
requestStream.Write(postDataBytes, 0, postDataBytes.Length);

requestStream.Close();

HttpWebResponse resp = (HttpWebResponse)request.GetResponse();
StreamReader responseReader = new StreamReader(resp.GetResponseStream(), Encoding.UTF8);
Response.Write(responseReader.ReadToEnd());

Thanks,
Jitender

apsmith
Site Admin
Posts: 2051
Joined: Wed Dec 31, 1969 8:00 pm

Re: Resume uploading and description updating in profile in c#

Post by apsmith » Wed Jul 20, 2011 11:24 am

Jitender,

The easiest way to see what is not functioning is to use a packet sniffer (Httpwatch) is one that I am using, to sniff your code vs the upload that is used from our test page and compare the two packets. You should be able to see where the difference is.

Also, can you verify that the userID you are using is a valid candidate or contact?
Andrew Smith
Director, Technical Operations
Developer Forum Admin

jitender
User
Posts: 18
Joined: Tue Mar 01, 2011 3:48 am

Re: Resume uploading and description updating in profile in c#

Post by jitender » Wed Jul 20, 2011 11:39 am

Hello apsmith,

Yes, 80277 is a valid candidate. If you need more details, please let me know.

Thanks,
Jitender

apsmith
Site Admin
Posts: 2051
Joined: Wed Dec 31, 1969 8:00 pm

Re: Resume uploading and description updating in profile in c#

Post by apsmith » Wed Jul 20, 2011 12:33 pm

Jitender,

Have you tried using the sniffer to see any differences?
Andrew Smith
Director, Technical Operations
Developer Forum Admin

jitender
User
Posts: 18
Joined: Tue Mar 01, 2011 3:48 am

Re: Resume uploading and description updating in profile in c#

Post by jitender » Thu Jul 21, 2011 12:36 am

Hello apsmith,

On comparing, I find that request is not going to AttachFile legacy API. Can you please check the following logs:

Log for AttachFileTestcfm

00:00:00.000 BullhornSTAFFING API: Attach File
+ 0.000 0.793 491 2007 GET 200 html http://www.bullhornstaffing.com/bullhor ... leTest.cfm
+ 0.843 0.836 641 329 GET 304 css http://www.bullhornstaffing.com/Bullhor ... 02%2E8%2E7
+ 0.845 0.735 640 4519 GET 200 css http://www.bullhornstaffing.com/Bullhor ... 02%2E8%2E7
+ 0.848 1.077 647 3725 GET 200 css http://www.bullhornstaffing.com/Bullhor ... 02%2E8%2E7
+ 0.850 0.882 642 330 GET 304 css http://www.bullhornstaffing.com/Bullhor ... 02%2E8%2E7
+ 0.852 0.919 644 332 GET 304 css http://www.bullhornstaffing.com/Bullhor ... 02%2E8%2E7
+ 0.854 0.964 640 328 GET 304 css http://www.bullhornstaffing.com/Bullhor ... 02%2E8%2E7
+ 0.856 1.161 638 326 GET 304 css http://www.bullhornstaffing.com/Bullhor ... 02%2E8%2E7
+ 0.859 1.198 642 330 GET 304 css http://www.bullhornstaffing.com/Bullhor ... 02%2E8%2E7
+ 0.861 0.149 0 0 GET (Cache) javascript http://www.bullhornstaffing.com/Bullhor ... etscape.js
+ 0.863 0.192 0 0 GET (Cache) javascript http://www.bullhornstaffing.com/Bullhor ... haviour.js
+ 0.865 0.230 0 0 GET (Cache) javascript http://www.bullhornstaffing.com/Bullhor ... ipicker.js
+ 0.867 0.266 0 0 GET (Cache) javascript http://www.bullhornstaffing.com/Bullhor ... s/rules.js
2.057 5625 12226 13 requests
00:00:00.969 0.277 0 0 GET (Cache) icon http://www.bullhornstaffing.com/favicon.ico
00:00:21.634 http://www.bullhornstaffing.com/Bullhor ... chFile.cfm
+ 0.000 2.359 27143 695 POST 200 html http://www.bullhornstaffing.com/Bullhor ... chFile.cfm
2.359 27143 695 1 request
00:00:24.087 0.042 0 0 GET (Cache) icon http://www.bullhornstaffing.com/favicon.ico

Log for local project on which I am working

00:00:19.350 http://localhost:55192/CandidateRegister.aspx
+ 32.621 0.069 0 0 GET (Cache) javascript http://localhost:55192/WebResource.axd? ... 6757546466
+ 32.619 0.328 380 1087 GET 200 html http://www.bridgenw.com/graphics/lookingforpl.jpg
+ 32.617 0.320 379 1087 GET 200 html http://www.bridgenw.com/graphics/ultraisLogo.gif
+ 32.615 1.100 360 2539 GET 404 html http://localhost:55192/css/dropdown-menu.css
+ 32.603 1.118 351 2530 GET 404 html http://localhost:55192/css/text.css
+ 0.000 32.548 91900 53036 POST 200 html http://localhost:55192/CandidateRegister.aspx
33.721 93370 60279 6 requests
00:00:00.000 http://localhost:55192/CandidateRegister.aspx
+ 2.268 0.061 0 0 GET (Cache) javascript http://localhost:55192/WebResource.axd? ... 6757546466
+ 2.266 0.353 380 1087 GET 200 html http://www.bridgenw.com/graphics/lookingforpl.jpg
+ 2.262 0.359 379 1087 GET 200 html http://www.bridgenw.com/graphics/ultraisLogo.gif
+ 2.260 1.089 360 2539 GET 404 html http://localhost:55192/css/dropdown-menu.css
+ 2.258 1.101 351 2530 GET 404 html http://localhost:55192/css/text.css
+ 0.000 2.220 350 52006 GET 200 html http://localhost:55192/CandidateRegister.aspx
3.359 1820 59249 6 requests

Thanks,
Jitender

apsmith
Site Admin
Posts: 2051
Joined: Wed Dec 31, 1969 8:00 pm

Re: Resume uploading and description updating in profile in c#

Post by apsmith » Thu Jul 21, 2011 9:46 am

Jitender,

I was suggesting using the sniffer to see the contents of the request, not the list of requests.

The important line to look at would be: "00:00:21.634 http://www.bullhornstaffing.com/Bullhor ... chFile.cfm"

If you can find the contents (the post params, content types, etc) and compare those against the same request from your code, you should see a difference.
Andrew Smith
Director, Technical Operations
Developer Forum Admin

jitender
User
Posts: 18
Joined: Tue Mar 01, 2011 3:48 am

Re: Resume uploading and description updating in profile in c#

Post by jitender » Fri Oct 28, 2011 9:59 am

Hello Apsmith,

Resume uploading was working fine but suddenly it stopped working. No error is coming but no resume is also attaching. Is there any change which I am not aware. Can you please help?

Thanks,
Jitender

jitender
User
Posts: 18
Joined: Tue Mar 01, 2011 3:48 am

Re: Resume uploading and description updating in profile in c#

Post by jitender » Mon Oct 31, 2011 6:20 am

Hi apsmith,

Any update on this..

Jitender

jitender
User
Posts: 18
Joined: Tue Mar 01, 2011 3:48 am

Re: Resume uploading and description updating in profile in c#

Post by jitender » Mon Oct 31, 2011 6:33 am

Attached is my code for your reference which used to work earlier:

Part #1
attachResume(savedCandidate.userID.ToString(), strFileNamePath, filename);

Part #2
public static string attachResume(string bhid, string resumeContent, string fileName)
{
try
{
CookieContainer cookies = new CookieContainer();
NameValueCollection querystring = new NameValueCollection();

querystring["privateLabelID"] = Globals.PrivateLabelID;
querystring["encryptedAPIKey"] = Globals.encryptedLegacyAPIKey;
querystring["userID"] = bhid;
querystring["updateResumeOverview"] = "TRUE";
querystring["userFile"] = resumeContent;

string outdata = FileAttach(resumeContent, "https://www.bullhorn.com/BullhornStaffi ... chFile.cfm", "userFile", "", querystring, cookies);

return outdata;
}
catch (Exception ex)
{
return "";
}
finally
{

}
}

Part #3

public static string FileAttach(string uploadfile, string url, string fileFormName, string contenttype, NameValueCollection querystring, CookieContainer cookies)
{
if ((fileFormName == null) ||
(fileFormName.Length == 0))
{
fileFormName = "file";
}

if ((contenttype == null) ||
(contenttype.Length == 0))
{
contenttype = "application/octet-stream";
}

string boundary = "----------" + DateTime.Now.Ticks.ToString("x");
StringBuilder sb = new StringBuilder();
FileStream fileStream = new FileStream(uploadfile, FileMode.Open, FileAccess.Read);

if (querystring != null)
{
foreach (string key in querystring.Keys)
{
switch (key)
{
case "userFile":
{
sb.Append("--");
sb.Append(boundary);
sb.Append("\r\n");
sb.Append("Content-Disposition: form-data; name=\"");
sb.Append(fileFormName);
sb.Append("\"; filename=\"");
sb.Append(Path.GetFileName(uploadfile));
sb.Append("\"");
sb.Append("\r\n");
sb.Append("Content-Type: ");
sb.Append(contenttype);
sb.Append("\r\n");
sb.Append("\r\n");
break;
}
default:
{
sb.Append("--");
sb.Append(boundary);
sb.Append("\r\n");
sb.Append("Content-Disposition: form-data; name=\"" + key + "\"");
sb.Append("\r\n");
sb.Append("\r\n");
sb.Append(querystring.Get(key));
sb.Append("\r\n");
sb.Append("\r\n");
break;
}
}
}
}
Uri uri = new Uri(url);

HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create(uri);
webrequest.CookieContainer = cookies;
webrequest.ContentType = "multipart/form-data; boundary=" + boundary;
webrequest.Method = "POST";

string postHeader = sb.ToString();
byte[] postHeaderBytes = Encoding.UTF8.GetBytes(postHeader);

// Build the trailing boundary string as a byte array
// ensuring the boundary appears on a line by itself
byte[] boundaryBytes = Encoding.ASCII.GetBytes("\r\n--" + boundary + "\r\n");


long length = postHeaderBytes.Length + fileStream.Length + boundaryBytes.Length;
webrequest.ContentLength = length;

Stream requestStream = webrequest.GetRequestStream();

// Write out our post header
requestStream.Write(postHeaderBytes, 0, postHeaderBytes.Length);

// Write out the file contents
byte[] buffer = new Byte[checked((uint)Math.Min(4096, (int)fileStream.Length))];
int bytesRead = 0;
while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) != 0)
requestStream.Write(buffer, 0, bytesRead);

// Write out the trailing boundary
requestStream.Write(boundaryBytes, 0, boundaryBytes.Length);
WebResponse responce = webrequest.GetResponse();
Stream s = responce.GetResponseStream();
StreamReader sr = new StreamReader(s);

return sr.ReadToEnd();
}

On reading, it returs blank document..This is the same code as mentioned on http://snipplr.com/view/9900/

Post Reply