Error while uploading atatchment to Google Sites - google-sites

Using the following code to upload an attachment to Google site, but I am getting an error as "Insert requests must contain an entry". I am using the code below:
FileInfo info = new FileInfo("C:\\Bluehills.txt");
FileStream stream = info.Open(FileMode.Open,FileAccess.ReadWrite,FileShare.ReadWrite);
this.setUserCredentials(userName, password);
Uri postUri = new Uri(makeFeedUri("content"));
// Send the request and receive the response:
AtomEntry insertedEntry = this.Insert(postUri, stream, (string)DocumentTypes["TXT"], "bluehills");
Any help please???

Fixed it myself after long search. Error was I was using AtomEntry in place of DocumentEntry... :)

Related

Issue when downloading a file from a folder in sharepoint document library in OFfice 365 using Microsoft Graph

I was able to get Drive object for my IT folder under my xxx.sharepoint.com teamsite in office 365
var drives = await graphClient.Sites["xxx.sharepoint.com"].Drives.Request().GetAsync();
//// Get https://xxx.sharepoint.com/IT drive
var driveIT = drives.CurrentPage.Where(d => d.DriveType == "documentLibrary" && d.Name == "IT").FirstOrDefault();
And, I was able to get the DriveItem object for a test.txt file under that IT folder
var testfile = await graphClient.Sites["xxx.sharepoint.com"].Drives[driveIT.Id].Root.ItemWithPath("test.txt").Request().GetAsync();
However, when I try to download the content I get this error
Code: invalidRequest
Message: Provided identifier is malformed - site collection id is not valid
// this cause the error
var streamtest = await graphClient.Sites["xxx.sharepoint.com"].Drives[driveIT.Id].Root.ItemWithPath("test.txt").Content
.Request()
.GetAsync();
// this also cause the same error.
//var streamtest = await graphClient.Sites["xxx.sharepoint.com"].Drives[driveIT.Id].Items[$"{testfile.Id}"].Content
// .Request()
// .GetAsync();
However, I am able to upload a text file under my IT folder.
var uploadedFile1 = await graphClient.Sites["xxx.sharepoint.com"].Drives[driveIT.Id].Root.ItemWithPath("New_testupload_msgraph.txt").Content.Request().PutAsync(stream1);
And, I was able to upload and download test files to/from my onedrive
var uploadedFile1 = await graphClient.Sites["xxx.sharepoint.com"].Drives[driveIT.Id].Root.ItemWithPath("New_testupload_msgraph.txt").Content.Request().PutAsync<DriveItem>(stream1);
var dlteststream = await graphClient.Me.Drive.Items["01JZT44T6EFIIYDTEEJNHLPJGYC3A4VO2H"].Content.Request().GetAsync();
Can any body help with this issue?
I tested your code in my SPO environment and i am able to reproduce this error.
I modified the code as below then it works well:
Change ...graphClient.Sites["xxx.sharepoint.com"]... to :
graphClient.Sites[siteid]
site id is like:
"abc.sharepoint.com,8f9xxxxxxx80e1e40d31,af1659xxxx-a12d-2a47800cc52d"
Here is my test demo, you may take a reference:
https://github.com/kongmengfei/sharedproject/blob/master/TeamifySharePointClassicSite/TeamifySharePointClassicSite/DownloadfileGraph.cs
BR

Azure Text to Speech started returning "400 Bad Request" all the sudden

I was using Azure Text-to-Speech API succesfully for months with this format:
<speak version='1.0' xmlns='w3.org/2001/10/synthesis' xml:lang='en-US'><voice name='Microsoft Server Speech Text to Speech Voice (fi-FI, HeidiRUS)'>My text</voice></speak>
But suddenly this request started returning:
HTTP/1.1 400 Bad request
We were using the same request successfully for months (with different phrase of course) but just some weeks ago the same request started returning this error. I don't get any additional information so I don't know where to look. Azure documentation says:
A required parameter is missing, empty, or null. Or, the value passed
to either a required or optional parameter is invalid. A common issue
is a header that is too long.
I also tried making the request more specific by adding gender and language and replacing single quotes with double quotes, but no use:
<speak version="1.0" xmlns="w3.org/2001/10/synthesis" xml:lang="fi-FI" xml:gender="Female"><voice name="Microsoft Server Speech Text to Speech Voice (fi-FI, HeidiRUS)">Text.</voice></speak>
Did something change in the API? Or what is missing in my request?
I got a 200 OK with the right content when I send the following payload:
<speak version='1.0' xmlns='http://www.w3.org/2001/10/synthesis' xml:lang='en-US'><voice name='Microsoft Server Speech Text to Speech Voice (fi-FI, HeidiRUS)'>This is my test</voice></speak>
Here is my C# code to send this:
// Generate request
string body = $#"<speak version='1.0' xmlns='http://www.w3.org/2001/10/synthesis' xml:lang='{voiceLang}'><voice name='{voiceName}'>{text}</voice></speak>";
using (var client = new HttpClient())
{
using (var request = new HttpRequestMessage())
{
// Set the HTTP method
request.Method = HttpMethod.Post;
// Construct the URI
request.RequestUri = new Uri(ttsHostUri);
// Set the content type header
request.Content = new StringContent(body, Encoding.UTF8, "application/ssml+xml");
// Set additional header, such as Authorization and User-Agent
request.Headers.Add("Authorization", "Bearer " + accessToken);
request.Headers.Add("Connection", "Keep-Alive");
// Update your resource name
request.Headers.Add("User-Agent", "YOUR_RESOURCE_NAME");
request.Headers.Add("X-Microsoft-OutputFormat", "riff-24khz-16bit-mono-pcm");
// Create a request
using (var response = await client.SendAsync(request).ConfigureAwait(false))
{
response.EnsureSuccessStatusCode();
// Asynchronously read the response
using (var dataStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false))
{
// ... Process your audio here
}
}
}
}
The only difference that I can see on our payloads is the xmlns value where I have a full url (with http://) whereas yours doesn't get it.
The error may be elsewhere: are you sure you are authenticating yourself when querying the endpoint?
We also suddenly got the 400 error and in our case we had missed to encapsulate the text for the XML request with
<![CDATA[ your text here ]]>
after we did that in our code we got no more reported 400 errors by the users.

Does DocuSign Connect Log include PDF Bytes?

While debugging my Connect listener (REST, Java), I am trying to create a PDF document based on xml in the Connect log for Demo. (I have to emulate Docusign POST request while security issues are being resolved.)
I have DocuSign Connect Service activated with “Include Documents” and "Include Certificate of Completion" checked.
I can see Attachment element in the log’s xml but not DocumentPDF element. When saving content as a byte array into PDF file and then trying to open it, it cannot be opened in Acrobat.
Is Attachment element in the Connect Log supposed to be a PDF document?
Here is my code to convert to pdf file:
String documentName = parseXMLDoc(xmlDoc, "DocumentStatus[1]/Name");
SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMdd HHmmsss");
String nowTime = fmt.format(new Date());
OutputStream out = new FileOutputStream("c:\\temp\\"+documentName.replaceAll(".pdf","_"+nowTime+".pdf"));
BASE64Decoder decoder = new BASE64Decoder();
String encodedBytes = parseXMLDoc(xmlDoc, "Attachment/Data");
byte[] decodedBytes = decoder.decodeBuffer(encodedBytes);
out.write(decodedBytes);
out.close();
where parseXMLDoc is
public static String parseXMLDoc(Document xmlDoc, String searchToken) {
String xPathExpression;
try {
XPath xPath = XPathFactory.newInstance().newXPath();
xPathExpression = "//" + searchToken;
return (xPath.evaluate(xPathExpression, xmlDoc));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
No the Connect log does NOT contain the actual document bytes... the documents are only included in the actual Connect pushes to your external listener. The log files simply contain metadata around the transaction, not the actual content.
You can possibly get a full response from DocuSign by using https://Webhook.site where you will be given a temporary URL for listening. Plug the temporary URL into the DocuSign Connection (create a new connection for testing), and open the XML packet from the dashboard on the webhook site dashboard when it arrives from DocuSign.

Issue while updating a doc when Sharepoint document ID service is activated

I am using sharepoint 2010 enterprise edition. I have activated Document ID service which will generate a doc Id for each doc when you upload. when i am first time uploading or saving the document it has no issues. It is getting saved. The issue i am facing is when i open the uploaded document and edit or update it and while saving it again it is giving the webexception "Underlying connection got disconnected. Connection closed prematurely".
I also tried to debug and found the response did not have header.
We were trying to perform in a windows application to edit and save the document.
we are trying to save the document by creating a webrequest.
please provide your idea on this issue.
please see the code below.
"
WebUrl webUrl = UrlToWebUrl(destinationUri);
System.Collections.Specialized.NameValueCollection methodData = new System.Collections.Specialized.NameValueCollection();
// Add general request to stream
methodData.Add("method","put document:" + GetServerExtensionsVersion(webUrl.SiteUrl));
methodData.Add("service_name","");
methodData.Add("put_option","overwrite,createdir,migrationsemantics");
methodData.Add("keep_checked_out","false");
HttpWebRequest req = StartWebRequest(GetAuthorURL(webUrl.SiteUrl), methodData);
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Ssl3;
System.IO.Stream reqStream = req.GetRequestStream();
RemoveSourceControlProperties(properties);
WriteDocumentData(reqStream, webUrl.FileUrl, file, properties);
reqStream.Flush();
reqStream.Close();
HttpWebResponse response = (HttpWebResponse)req.GetResponse();
try
{
if (!PutDocumentResponseSuccess(GetResponseString(response)))
{
throw new FrontPageRPCException("Failed to save document.", destinationUri);
}
}
finally
{
if (null != response) response.Close();
}
}
"

Download file with url as http://<site collection>/_layouts/DocIdRedir.aspx?ID=<doc id> using web request

I have a site collection in which Document Id feature is activated.
Documents are archived to this site collection from another site (in which Document Id is activated as well) and the only information I have about the moved file is the document id which is same between the source and the destination.
I need to download the file using web request, but my code gives '401 Unauthorised Exception'.
My code is as below:
string url = "http://<site collection>/_layouts/DocIdRedir.aspx?ID=<doc id>";
HttpWebRequest request = HttpWebRequest.Create(url) as HttpWebRequest;
request.Method = "Get";
request.PreAuthenticate = true;
var credential= new NetworkCredential(username, password, domainname);
request.Credentials = credential;
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
I need to give some sort of authentication, but could not figure it out.
Any help would be greatly appreciated.
Thanks and Regards
Arjabh
Try running your code inside of a
SPSecurity.RunWithElevatedPrivileges(delegate()
{
//code goes here
});
block

Resources