Page 1 of 1

File Attaching

Posted: Wed Nov 02, 2011 8:37 am
by jitender
Hello Apsmith,

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

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 returns blank document..This is the same code as mentioned on http://snipplr.com/view/9900/

Thanks,
Jitender

Re: File Attaching

Posted: Thu Nov 17, 2011 3:55 pm
by MMartin4
Hi jitender,

It looks like you were impacted by an issue that affected some of our clients when uploading files via the Legacy API. When things like this happen, you should check in with Bullhorn Support. This should have went back to normal a week or so ago. You should be all set with this particular issue.

Re: File Attaching

Posted: Mon Nov 28, 2011 1:31 am
by jitender
Hello MMartin4,

Thanks for replying. I tested today and found that I am getting error "Invalid encryptedAPIKey". Although same Key works fine when i upload file from http://www.bullhornstaffing.com/bullhor ... leTest.cfm. I have compared the two entered in application and the one i use in AttachFiletest.cfm and they are fine. Please help!

Thanks,
Jitender

Re: File Attaching

Posted: Mon Nov 28, 2011 11:10 am
by MMartin4
Jitender,

This is a case where you'd want to contact Support. You'll do this directly if you are a direct contact for one of our clients, or through our mutual client if you have been hired as a third party. We'd need to take a look a verify some of the details here and for security purposes we'd need to have that exchange via the channel provided by Bullhorn Support. Our analysts should be able to help troubleshoot and triage appropriately.

Do this as soon as you can so the assistence process can begin.

Re: File Attaching

Posted: Mon Nov 28, 2011 11:48 pm
by jitender
Hello MMartin4,

Thanks for your assistance. I am able to solve the issue. Issue was change of AttachFile.cfm url.

Thanks,
Jitender