I have a snippet of code that has been working fine up until a week ago, and now it errors out and the exception says 403 Forbidden. I have been reading that maybe adding "DefaultCredentials" may help, but I am not sure how to apply that to my code.
I am trying to pull data from: http://na.leagueoflegends.com/en/rss.xml
and my code that was working fine is:
XDocument xmlFile = XDocument.Load(#"http://na.leagueoflegends.com/en/rss.xml");
var LoLtitles = from service in xmlFile.Descendants("item")
select (string)service.Element("title");
var LoLlinks = from service in xmlFile.Descendants("item")
select (string)service.Element("link");
var LoLdescriptions = from service in xmlFile.Descendants("item")
select (string)service.Element("description");
var LoLDates = from service in xmlFile.Descendants("item")
select (string)service.Element("pubDate");
var servicing = LoLdescriptions.ToArray();
for (int i = 0; i < 4; i++)
{
servicing[i] = Regex.Replace(Server.HtmlDecode(servicing[i]), #"<[^>]*>", String.Empty);
}
ViewBag.titles = LoLtitles.ToArray();
ViewBag.links = LoLlinks.ToArray();
ViewBag.descriptions = servicing;
ViewBag.dates = LoLDates.ToArray();
But now the XDocument.Load line is getting a forbidden exception. I can still manually go the .xml's url page and see the file/text, so I am not sure why my program is being denied access all of the sudden...
I have browsed around and I am trying to figure out how to do the Default Credentials approach that people have used for URL/Web requests, however I do not know how to tack that onto XDocument (or an equivalent approach).
Related
I have the following code to add title tab to the DocuSign document - not a template - in C#.
It has worked up until now, but today the tab on the document comes up vertically, so all characters in the title show up vertically.
I am only seeing this when I go to correct the document on DocuSign web site. It does not show that way when I receive for signature. I was not correcting anything, but just checking to ensure that everything was as expected.
Instead of
Manager
it comes up as
M
a
n
a
g
e
r
How can I fix that? The code is below.
tab13.PageNumber = "17";
tab13.DocumentID = docId;
tab13.Type = DocuSignAPI.TabTypeCode.Custom;
tab13.CustomTabType = DocuSignAPI.CustomTabType.Text;
tab13.Name = "txtTitle";
tab13.Value = mgrTitle;
tab13.CustomTabTypeSpecified = true;
tab13.AnchorTabItem = new DocuSignAPI.AnchorTab();
tab13.AnchorTabItem.AnchorTabString = "Title:";
tab13.AnchorTabItem.Unit = DocuSignAPI.UnitTypeCode.Pixels;
tab13.AnchorTabItem.UnitSpecified = false;
tab13.AnchorTabItem.IgnoreIfNotPresent = true;
tab13.AnchorTabItem.UnitSpecified = true;
tab13.AnchorTabItem.YOffset = -20;
tab13.AnchorTabItem.XOffset = 50;
I am only seeing this when I go to correct the document on DocuSign web site. It does not show that way when I receive for signature. I was not correcting anything, but just checking to ensure that everything was as expected.
The other day I had my scraper working very well, when I realized that I wasn't getting enough records, I decided to search by postal code and had to change some of my code. The first POST and RESPONSE goes off without a hitch, but when I post to get the next page of results it fails on the Response.
the starting code is...
public void StartScrape()
{
List<string> a = lstPostalCodes();
for (int i = 0; i <= lstPostalCodes().Count; i++)
{
b = a[i];
FirstRequestResponse(b);
if (GoBackToStartSearch == "CONTINUEON")
StartNextRequest(GetViewState(ResponseData));
else
{
WriteDataToFile(ResponseData);
FinalClean();
}
}
}
The method that I am calling is StartNextRequest. In the StartNextRequest method is
private void GetResults(HttpWebRequest wr)
{
using (StreamReader responseReader = new StreamReader(wr.GetResponse().GetResponseStream()))
{
// Add response/results to string
ResponseData = responseReader.ReadToEnd();
}
string strFind = "<li id='nextdisabled'>";
if (ResponseData.Contains(strFind)) GoBackToStartSearch = "BACKTOSTART";
else
GoBackToStartSearch = "CONTINUEON";
}
The error that its throwing is saying that the
Input string was not in correct format
and pointing at the using (StreamReader...)
I have gotten other errors that I seem to fix, but then it creates another error which has to do with waiting for bytes to be written. I'm using Fiddler2 to give me more info on the errors, the headers are pretty much the same, I'm not seeing much of a difference, other than 1 being a request and the other a response.
I have no idea on why its saying that, I have stepped through the working code that I wrote to scrape all the data results, and compared the two. Everything looks the same. The values are all the same.
Any ideas on where I should look to fix this?
I have created users using CreateOrUpdateUser() method but i was unable to fetch all the users from zendesk. I am getting null for "oListUser" also I tried to fetch user list for Organization but for that also i am getting null.Any help would be appreciated. There is no issue with the connection.
Code:
ZenDeskApi.ZenDeskApi oZen = new ZenDeskApi.ZenDeskApi("https://waresolution.zendesk.com", "j#se.com", "87ggh76IO");
List<User> oListUser = oZen.GetUsers();
User oUsers = new ZenDeskApi.Model.User();
oUsers.Email = "r#se.com";
oUsers.IsVerified = true;
oUsers.Name = "R r";
oUsers..........// Other properties
int a = oZen.CreateOrUpdateUser(oUsers);
List<Organization> oOrg = oZen.GetOgranizations();
foreach (var orgItem in oOrg)
{
int orgId = orgItem.Id;
}
Take a look at this zendesk api client for C#.net on Github. See the JUSTEAT blog for more details. You can use this client to get all users like this:
Create a client:
IZendeskClient client = new ZendeskClient(
new Uri("my-zendesk-api-host-endpoint"),
"my-zendesk-username",
"my-zendesk-token"
);
Then you can use the Search resource to search all users:
var result = client.Search.Find(new ZendeskQuery<User>().WithCustomFilter("y", "x"));
You can download the code as a Nuget here
I am using ZendeskApi_v2 and I am able to get all the users using api as follows:
var userList = api.Users.GetAllUsers();
Here userList is GroupUserReponse.I doubt whether we have any method GetUsers().Atleast its not available in the version which I am using.Once you get the response you can iterate through it.
I see that this question is related to ZenDeskApi which is available at this location:
https://github.com/eneifert/ZenDeskApi.
Sorry,I have not worked on it and tried this.
Not sure if you got a response to this but for anyone else looking for info on the API:
Try instead of:
ZenDeskApi.ZenDeskApi oZen = new ZenDeskApi.ZenDeskApi("https://waresolution.zendesk.com", "j#se.com", "87ggh76IO");
ZenDeskApi.ZenDeskApi oZen = new ZenDeskApi("https://waresolution.zendesk.com", "j#se.com", "87ggh76IO");
Also, to get a paginated list of 100 users instead of the group response, just call:
var zendeskUsers = oZen.Users.GetAllUsers().Users;
I'm having following code which runs perfectly on dev server but gives error on live server.
It gives me following error
System.UriFormatException: Invalid URI: The format of the URI could not be determined.
Please guide me how to resolve this issue.
<-----------------Code Started--------------------->
private void InsertThrAPI(clsProductProp objProductProp)
{
xmldata data = new xmldata();
data.Items = new xmldataProducts[1];
data.Items[0] = new xmldataProducts();
objProduct.stockstatus = Convert.ToString(objProductProp.stockstatus);
objProduct.price = Convert.ToString(objProductProp.price);
objProduct.productname = Convert.ToString(objProductProp.productname);
objProduct.productshortname = Convert.ToString(objProductProp.productshortname);
objProduct.productcode = Convert.ToString(objProductProp.productcode);
objProduct.description = Convert.ToString(objProductProp.description);
objProduct.technicalspecs = Convert.ToString(objProductProp.technicalspecs);
objProduct.shippingcost = Convert.ToString(objProductProp.shippingcost);
objProduct.productweight = Convert.ToString(objProductProp.productweight);
objProduct.vendorprice = Convert.ToString(objProductProp.vendorprice);
if (objProductProp.shipping == true || objProductProp.shipping == Convert.ToBoolean(1))
{
objProduct.shipping = "Y";
}
else
{
objProduct.shipping = "N";
}
//Populate the product fields here
data.Items[0].StockStatus = objProduct.stockstatus;
data.Items[0].ProductPrice = objProduct.price;
data.Items[0].ProductName = objProduct.productname;
data.Items[0].ProductNameShort = objProduct.productshortname;
data.Items[0].ProductCode = objProduct.productcode;
data.Items[0].ProductDescription = objProduct.description;
data.Items[0].TechSpecs = objProduct.technicalspecs;
data.Items[0].FreeShippingItem = objProduct.shipping;
data.Items[0].Fixed_ShippingCost = objProduct.shippingcost;
data.Items[0].ProductWeight = objProduct.productweight;
data.Items[0].Vendor_Price = objProduct.vendorprice;
string productXML = Utils.GetProductXML(data);
string APIURL = Utils.GetAPIPostURL(ImportMode.Insert);
XMLPostManager manager = new XMLPostManager();
string response = manager.SendXMLToURL(APIURL, productXML);
//Response.Write(response);
}
We would need to see the URL to tell you what's wrong with it, but you can check to make sure that the URL is valid like this:
if (Uri.IsWellFormedUriString(APIURL, UriKind.RelativeOrAbsolute))
{
//url is valid
}
Please guide me how to resolve this issue.
I guess you main problem is that this only happens in live and not in your dev system, so debugging is hard?
A couple of suggestion:
Look in to adding logging code - there's a lot of info out there, but
something like Log4Net would be a good start. Add logging code
to this method and you should hopefully see the data that is causing
issues.
See if you can add more realistic data to your unit tests or
other internal tests and see if you can spot this.
I am attempting to load document files into a document library in SharePoint using the CopyIntoItems method of the SharePoint Copy web service.
The code below executes and returns 0 (success). Also, the CopyResult[] array returns 1 value with a "Success" result. However, I cannot find the document anywhere in the library.
I have two questions:
Can anyone see anything wrong with my code or suggest changes?
Can anyone suggest how I could debug this on the server side. I don't have a tremendous amount of experience with SharePoint. If I can track what is going on through logging or some other method on the server side it may help me figure out what is going on.
Code Sample:
string[] destinationUrls = { Uri.EscapeDataString("https://someaddress.com/Reports/Temp") };
SPCopyWebService.FieldInformation i1 = new SPCopyWebService.FieldInformation { DisplayName = "Name", InternalName = "Name", Type = SPListTransferSpike1.SPCopyWebService.FieldType.Text, Value = "Test1Name" };
SPCopyWebService.FieldInformation i2 = new SPCopyWebService.FieldInformation { DisplayName = "Title", InternalName = "Title", Type = SPListTransferSpike1.SPCopyWebService.FieldType.Text, Value = "Test1Title" };
SPCopyWebService.FieldInformation[] info = { i1, i2 };
SPCopyWebService.CopyResult[] result;
byte[] data = File.ReadAllBytes("C:\\SomePath\\Test1Data.txt");
uint ret = SPCopyNew.CopyIntoItems("", destinationUrls, info, data, out result);
Edit that got things working:
I got my code working by adding "http://null" to the SourceUrl field. Nat's answer below would probably work for that reason. Here is the line I changed to get it working.
// Change
uint ret = SPCopyNew.CopyIntoItems("http://null", destinationUrls, info, data, out result);
I think the issue may be in trying to set the "Name" property using the webservice. I have had some fail doing that.
Given the "Name" is the name of the document, you may have some success with
string targetDocName = "Test1Name.txt";
string destinationUrl = Uri.EscapeDataString("https://someaddress.com/Reports/Temp/" + targetDocName);
string[] destinationUrls = { destinationUrl };
SPCopyWebService.FieldInformation i1 = new SPCopyWebService.FieldInformation { DisplayName = "Title", InternalName = "Title", Type = SPListTransferSpike1.SPCopyWebService.FieldType.Text, Value = "Test1Title" };
SPCopyWebService.FieldInformation[] info = { i1};
SPCopyWebService.CopyResult[] result;
byte[] data = File.ReadAllBytes("C:\\SomePath\\Test1Data.txt");
uint ret = SPCopyNew.CopyIntoItems(destinationUrl, destinationUrls, info, data, out result);
Note: I have used the "target" as the "source" property. Don't quite know why, but it does the trick.
I didn't understand very well what you're tying to do, but if you're trying to upload a file from a local directory into a sharepoint library, i would suggest you create a webclient and use uploadata:
Example (VB.NET):
dim webclient as Webclient
webClient.UploadData("http://srvasddress/library/filenameexample.doc", "PUT", filebytes)
Then you just have to check in the file using the lists web service, something like:
listService.CheckInFile("http://srvasddress/library/filenameexample.doc", "description", "1")
Hope it was of some help.
EDIT: Don't forget to set credentials for the web client, etc.
EDIT 2: Update metada fields using this:
listService.UpdateListItems("Name of the Library, batchquery)
You can find info on building batch query's in here: link
The sourceurl is used in Sharepoint. It is a link back to the "Source Document." When in your document library, hover over the item, to the right appears a down pointing triangle. Clicking on it, brings up a menu. Click on the "View Properties" Option. On this page you will see the following "This item is a copy of http://null ( Go To Source Item | Unlink )"
Because we are using the Copy function Sharepoint is keeping track of the "Source item" as part of the Document Management feature.