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

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();
}
}
"

Related

How to download documents from liferay from outside application ..using liferay jsonws or any other way

Hi i am using liferay/api/secure/jsonws services to upload documents, getting documents, from a outside application , in the same way i want to download the documents also, i checked my liferay jsonws , there is no method or service which i can use for download , or i don't know about it , please suggest me a way to download documents from outside application , by using jsonws or any other way is also fine.
Edit after i got to know how to download document.
Hi I tried to download liferay document from outside application by using getURl, but every time for all document i am getting liferay login page content
i have already tried get-file-as-stream json-rpc call but that also giving me null response
the code which i have used is:
final HttpHost targetHost = new HttpHost(hostname.trim());
System.out.println(targetHost.getHostName());
UsernamePasswordCredentials creds = new UsernamePasswordCredentials(username, password);
System.out.println(creds);
final AuthScope authscope = new AuthScope(targetHost);
httpclient.getCredentialsProvider().setCredentials(authscope, creds);
final AuthCache authCache = new BasicAuthCache();
final BasicScheme basicAuth = new BasicScheme();
authCache.put(targetHost, basicAuth);
final BasicHttpContext localContext = new BasicHttpContext();
localContext.setAttribute(ClientContext.AUTH_CACHE, authCache);
final HttpGet httpget = new HttpGet(hostname+"/documents/" + groupId + "/" + folderId + "/" + filename);
final HttpResponse response = httpclient.execute( httpget, localContext);
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
final org.apache.http.HttpEntity entity = response.getEntity();
if (entity != null) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
entity.writeTo(baos);
return baos.toByteArray();
}
}
return null;
} finally {
httpclient.getConnectionManager().shutdown();
}
}
i am adding basic auth header will correct username and password, don't know how this login page is coming, is there any permission which i need to change or any configurations issue, please help in this.
You could use the Liferay WebDav Services to download files from your document-library. The paths to download can be inspected inside of the control-panel when clicking on a file entry (WebDAV URL toogle link). The paths usually look like: /webdav/{site-name}/document_library/{folder-name}/{file-name}
Otherwise, you could mimic the request URLs Liferay creates inside the documents-media portlet to download the file entry.
But you should take care about authentication, when your files (and folders) are not visible to guests.

OneDrive Copy Item using Microsoft Graph SDK - GatewayTimeout at 10 seconds if ~>38mb file

I am using the MS Graph .net SDK. Attempting to copy a sharepoint document library to another sharepoint document library.
If the file is approximately 38mb, a GatewayTimeout exception is thrown for an unknown error.
Either MS has a bug, or I am doing something incorrectly. Here is my code:
HttpRequestMessage hrm = new HttpRequestMessage(HttpMethod.Post, request.RequestUrl);
hrm.Content = new StringContent(JsonConvert.SerializeObject(request.RequestBody), System.Text.Encoding.UTF8, "application/json");
await client.AuthenticationProvider.AuthenticateRequestAsync(hrm);
HttpResponseMessage response = await client.HttpProvider.SendAsync(hrm);
if (response.IsSuccessStatusCode)
{
var content = await response.Content.ReadAsStringAsync();
}
}
catch (Microsoft.Graph.ServiceException ex)
{
throw new Exception("Unknown Error");
}
Anyone see a problem here?
EDIT: Here is my revised code
public static async Task copyFile(Microsoft.Graph.GraphServiceClient client, string SourceDriveId, string SourceItemId, string DestinationDriveId, string DestinationFolderId, string FileName)
{
try
{
var destRef = new Microsoft.Graph.ItemReference()
{
DriveId = DestinationDriveId,
Id = DestinationFolderId
};
await client.Drives[SourceDriveId].Items[SourceItemId].Copy(null, destRef).Request().PostAsync();
//await client.Drives[SourceDriveId].Root.ItemWithPath(itemFileName).Copy(parentReference: dest).Request().PostAsync();
}
catch (Microsoft.Graph.ServiceException ex)
{
throw new Exception(ex.Message);
}
}
The above revised code continues to give the same error; however, tonight, it is also occurring on a 13.8mb file that previously had worked fine.
Logically, because the error doesn't occur for smaller files, I think it has something to do with file size.
The response is supposed to be a 202 with location header. See Copy Item in Graph Docs; however, I have never been able to obtain a location header. I suspect that Microsoft Graph is not getting the location header information from the OneDrive API and is therefore throwing a Gateway Timeout error.
I believe this is what you're looking for:
await graphClient.Drives["sourceDriveId"]
.Items["sourceItemId"]
.Copy(null, new ItemReference()
{
DriveId = "destinationDriveId",
Id = "destinationFolderId"
})
.Request()
.PostAsync();
This will take a given DriveItem and copy it to a folder in another Drive.

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.

File uploading from web application to Sharepoint server

This is my first time ever with Sharepoint. Here is the scenario
I have a stand alone web application
I also have a stand alone sharepoint server.
Both are on different servers.
I need to upload a file from web application to sharepoint
I found 2 methods online,
Using the webservice provided by Sharepoint (CopyIntoItems)
Using jQuery library of Sharepoint webservice
After searching the web, I think the jQuery part will not work (you can correct me).
I am looking for a method that takes username/password and uploads a pdf file to Sharepoint server. The following is my C# code that tries to upload but ends up in error
public bool UploadFile(string file, string destination)
{
bool success = false;
CopySoapClient client = new CopySoapClient();
if (client.ClientCredentials != null)
client.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
try
{
client.Open();
string filename = Path.GetFileName(file);
string destinationUrl = destination + filename;
string[] destinationUrls = { destinationUrl };
FieldInformation i1 = new FieldInformation { DisplayName = "Title", InternalName = "Title", Type = FieldType.Text, Value = filename };
FieldInformation[] info = { i1 };
CopyResult[] result;
byte[] data = File.ReadAllBytes(file);
//uint ret = client.CopyIntoItems(filename, destinationUrls, info, data, out result);
uint ret = client.CopyIntoItems(file, destinationUrls, info, data, out result);
if (result != null && result.Length > 0 && result[0].ErrorCode == 0)
success = true;
}
finally
{
if (client.State == System.ServiceModel.CommunicationState.Faulted)
client.Abort();
if (client.State != System.ServiceModel.CommunicationState.Closed)
client.Close();
}
return success;
}
I am calling the above function like this
UploadFile(#"C:\temp\uploadFile.txt", "http://spf-03:300/demo/Dokumente").ToString();
Error that i get:
Error Code: Destination Invalid
Error Message: The service method 'Copy' must be called on the same domain that contains the target URL.
There is the 3rd option with SharePoint 2010 and that is to use the Client Side object model. The client side object model a a sub set of the larger Sharepoint API, but it does cover uploading documents. Below is blog post with an example of uploading.
Upload document through client object model
As with most things in SharePoint you will need to authenticate against it the site, so find out if your site collection is forms based or claims based and then you should be able to find sample code for your situation.
Solution to the problem:
The problem was that the "security token webservice" was not working and it was giving some error when we manually ran the webservice.
The server was unable to process the request due to an internal error.
For more information about the error, either turn on
IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute
or from the configuration behavior) on the server in order to send the
exception information back to the client, or turn on tracing as per
the Microsoft .NET Framework 3.0 SDK documentation and inspect the
server trace logs.
The above exception is a generic one. To view the exact exception we enabled remote error viewing from the web.config file of the webservice(link) and saw the exact exception.
We found the solution for the exception and the service started. After that everything was working fine.

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