After upload files into ever-note, All Files are showing with same name - evernote

I have created copies of a file, name as A.pdf, B.pdf, C.pdf(same files with different names).
after i uploaded these files into ever-note, All Files are showing with same name. (A.pdf, A,pdf, A.PDF)
I have checked this in Evernote web application.

To change the filename that appears in Evernote (and upon download) use the note attribute object and set the fileName attribute to the name of the file. Then attach the noteAttribute object to the resource by setting the attributes property of the resource object to the ResourceAttribute Object.
Example in Python:
import evernote.edam.type.ttypes as Types
#create the resource object
resource = Types.Resource()
resource.data = data
#get the hash to reference in ENML
hash_hex = binascii.hexlify(fileHash)
#write note contents
note.content = '<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd"><en-note><br/>Excel File:<en-media type="application/excel" hash="' + hash_hex + '"/></en-note>'
#create Resource Attribute Object
ra = Types.ResourceAttributes()
ra.fileName = "report.xlsx" #set the filename you wish to appear in the note
ra.attachment= True
#attach the resource attribute object to the resource object
resource.attributes = ra
note.resources = [resource] # Now, add the new Resource to the note's list of resources

Related

Download an externalReference from PlannerTask using the Graph API

I'd like to download a file attached to a PlannerTask. I already have the external references but I can't figure out how to access the file.
An external reference is a JSON object like this:
{
"https%3A//contoso%2Esharepoint%2Ecom/sites/GroupName/Shared%20Documents/AnnualReport%2Epptx":
{
// ... snip ...
}
}
I've tried to use the following endpoint
GET /groups/{group-id}/drive/root:/sites/GroupName/Shared%20Documents/AnnualReport%2Epptx
but I get a 404 response. Indeed, when I use the query in Graph Explorer it gives me a warning about "Invalid whitespace in URL" (?).
A workaround that I've found is to use the search endpoint to look for files like this:
GET /groups/{group-id}/drive/root/search(q='AnnualReport.pptx')
and hope the file name is unique.
Anyway, with both methods I need extra information (ie. the group-id) that may not be readily available by the time I have the external reference object.
What is the proper way to get a download url for a driveItem that is referenced by an external reference object in a PlannerTask?
Do I really need the group-id to access such file?
The keys in external references are webUrl instances, so they can be used with the /shares/ endpoint. See this answer for details on how to do it.
When you get a driveItem object, the download url is available from AdditionalData: driveItem.AdditionalData["#microsoft.graph.downloadUrl"]. You can use WebClient.DownloadFile to download the file on the local machine.
Here is the final code:
var remoteUri = "https%3A//contoso%2Esharepoint%2Ecom/sites/GroupName/Shared%20Documents/AnnualReport%2Epptx";
var localFile = "/tmp/foo.pptx";
string sharingUrl = remoteUri;
string base64Value = System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(sharingUrl));
string encodedUrl = "u!" + base64Value.TrimEnd('=').Replace('/','_').Replace('+','-');
DriveItem driveItem = m_graphClient
.Shares[encodedUrl]
.DriveItem
.Request()
.GetAsync().Result;
using (WebClient client = new WebClient())
{
client.DownloadFile(driveItem.AdditionalData["#microsoft.graph.downloadUrl"].ToString(),
localFile);
}

Uploading files to Blob & getting error: C:\Program Files (x86)\IIS Express\

I tried to upload file to blob. But I'm getting error like this:
"'C:\Program Files (x86)\IIS
Express\Nominative-Officers-Entry-Form-Stu.docx'."
I don't use HttpPostedFileBase in my code. I just pass object to my controller with files to be uploaded. Lease tell me what I'm doing wrong?
I want to know wt this line means :
"blockBlob.Properties.ContentType = "
This is my code:
public static SaveResponses CreateFile(Blob_Storage_Header docDetails)
{
string storageConnectionString = ConfigurationManager.ConnectionStrings["StorageConnectionString"].ConnectionString.ToString();
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(storageConnectionString);
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer container = blobClient.GetContainerReference("test2");
ICollection<Blob_Storage_Details> BlobStorageDetails = docDetails.Blob_Storage_Details;
if (BlobStorageDetails.Count > 0) {
foreach (Blob_Storage_Details item in BlobStorageDetails)
{
string DocUUID = Guid.NewGuid().ToString();
CloudBlockBlob blockBlob = container.GetBlockBlobReference(DocUUID + item.Blob_Name);
var fileName = Path.GetFileName(item.Blob_Name);
//blockBlob.Properties.ContentType = item.ContentType;
// Create or overwrite the "myblob" blob with contents from a local file.
using (var fileStream = File.OpenRead(fileName))
{
blockBlob.UploadFromStream(fileStream);
}
}
}
SaveResponses saveResponse = new SaveResponses();
saveResponse.saveStatus = "true";
saveResponse.messageType = "success";
saveResponse.message = "File Create message";
return (saveResponse);
}
"'C:\Program Files (x86)\IIS Express\Nominative-Officers-Entry-Form-Stu.docx'."
Based on your code, I ran it on my side, then I got the following error:
Remark: In development environment, you could add “<customErrors mode="Off"/>” within the system.web node in your Web.config file, then you could view the detailed errors.
According to this error, I checked and found the specified file path was not existed.
After some trials, I fixed the issue on my side. Please follow the descriptions below to check your code to see whether it works:
a) Please pay attention to the code “Path.GetFileName”, it returns the file name and extension of the specified path string (e.g. settings.job).
b) Make sure that the filename that is used in “File.OpenRead(fileName)” is an absolute file path and the file is existed in your environment.
"blockBlob.Properties.ContentType = "
Azure Storage Client Library for .NET is based on Storage Service REST API,
From the official document we could find that “blockBlob.Properties.ContentType” represents the MIME content type of the blob, the default type is application/octet-stream.
MIME is a way to identity files on internet according to their nature and format. For example, using the "Content-type" header value defined in a HTTP response, the browser can open the file with the proper extension/plugin. For more details about MIME, please refer to this link: http://www.freeformatter.com/mime-types-list.html

DotCMIS IDocument does not give file path

I have an Alfresco 4.2 document at /Sites/swsdp/documentLibrary/Presentations/test1.txt with id workspace://SpacesStore/626216a1-5f9e-4010-a424-e2e0ec4f2663;1.0.
Here is my DotCMIS code to deal with a ChangeLog change event:
ICmisObject cmisObject = session.GetObject(
"workspace://SpacesStore/626216a1-5f9e-4010-a424-e2e0ec4f2663;1.0");
if (null != (document = cmisObject as IDocument))
{
String filename = document.ContentStreamFilename; // returns: "test1.txt"
List<String> paths = document.Paths; // returns: Empty list
}
Why is paths an empty list?
Why does it not contain /Sites/swsdp/documentLibrary/Presentations/test1.txt?
I know it is not exactly the same, but OpenCMIS documentation says this for the same method:
Returns the list of paths of this object or an empty list if this object is unfiled or if this object is the root folder
The problem is that I was using the old CMIS URL of Alfresco.
It is solved by using the new URL format:
http://<host>/alfresco/api/-default-/public/cmis/versions/1.0/atom
This isn't an answer but I can't add a comment since my rep is too low.
It works for me. I got a document's path using an Alfresco 4.2 system
btw, your code should be
String filename = document.ContentStreamFileName; //camel case
IList<String> paths = document.Paths; //IList vs List

Is there way to read a text file from an assembly by using Reflection in C#?

I have a text file inside the assembly say MyAssembly. I am trying to access that text file from the code like this :
Stream stream = Assembly.GetAssembly(typeof(MyClass)).GetFile("data");
where data is data.txt file containing some data and I have added that .txt as Embedded Resources. I have dome reading of the images from the Assebly as embedded resources with code like this :
protected Stream GetLogoImageStream()
{
Assembly current = Assembly.GetExecutingAssembly();
string imageFileNameFormat = "{0}.{1}";
string imageName = "myLogo.GIF";
string assemblyName = current.ManifestModule.Name;
int extensionIndex = assemblyName.LastIndexOf(".dll", StringComparison.CurrentCultureIgnoreCase);
string file = string.Format(imageFileNameFormat, assemblyName.Remove(extensionIndex, 4), imageName);
Stream thisImageStream = current.GetManifestResourceStream(file);
return thisImageStream;
}
However, this approach did not work while reading the .txt file from an the executing assembly. I would really appreciate if anybody can point me to the approach to read .txt file from an assembly. Please dont ask me why I am not reading the file from the drive or the network share. Just say that the requirement is to read the .txt file from the Assembly.
Thank you so much
GetManifestResourceStream is indeed the correct way to read the data. However, when it returns null, that usually means you have specified the wrong name. Specifying the correct name is not as simple as it seems. The rules are:
The VB.NET compiler generates a resource name of <root namespace>.<physical filename>.
The C# compiler generates a resource name of <default namespace>.<folder location>.<physical filename>, where <folder location> is the relative folder path of the file within the project, using dots as path separators.
You can call the Assembly.GetManifestResourceNames method in the debugger to check the actual names generated by the compiler.
Your approach should work. GetManifestResourceStream returns null, if the resource is not found. Try checking the run-time value of your file variable with the actual name of the resource stored in the assembly (you could check it using Reflector).
I really appreciate for everybody's help on this question. I was able to read the file with the code like this :
Assembly a = Assembly.GetExecutingAssembly();
string[] nameList = a.GetManifestResourceNames();
string manifestanme = string.Empty;
if (nameList != null && nameList.Length > 0)
{
foreach (string name in nameList)
{
if (name.IndexOf("c.txt") != -1)
{
manifestanme = name;
break;
}
}
}
Stream stream = a.GetManifestResourceStream(manifestanme);
Thanks and +1 for Christian Hayter for this method : a.GetManifestResourceNames();

How to specify the namespace when referencing a table in a dataset

I'm loading data into a DataSet from an XML file using the ReadXml method. This results in two tables with the same name. One of the tables has a namespace and the other doesn't. I'm trying to reference the table with the namespace. Can anyone tell me how to do this?
Dim reader As XmlTextReader = New XmlTextReader(strURL)
Dim city as string = ""
Dim ds As DataSet = New DataSet()
ds.Namespace = "HomeAddress"
ds.ReadXml(reader)
city = ds.Tables("Address").Rows(0).Item(2).ToString()
From MSDN: DataSet.Namespace
The Namespace property is used when
reading and writing an XML document
into the DataSet using the ReadXml,
WriteXml, ReadXmlSchema, or
WriteXmlSchema methods.
The namespace of an XML document is
used to scope XML attributes and
elements when read into a DataSet. For
example, if a DataSet contains a
schema that was read from a document
with the namespace "myCompany," and an
attempt is made to read data only from
a document with a different namespace,
any data that does not correspond to
the existing schema is ignored.
The following example sets the Prefix
before calling the ReadXml method.
private void ReadData(DataSet thisDataSet)
{
thisDataSet.Namespace = "CorporationA";
thisDataSet.Prefix = "DivisionA";
// Read schema and data.
string fileName = "CorporationA_Schema.xml";
thisDataSet.ReadXmlSchema(fileName);
fileName = "DivisionA_Report.xml";
thisDataSet.ReadXml(fileName);
}
I cant see from the example you gave, but unless you set your prefix before you load, you wont be able to read data that doesn't correspond to the existing schema.
I found the answer. You can pass in the namespace as the second parameter. I guess I didn't notice this particular overload in Intellisense.
ds.Tables("Address", "HomeAddress").Rows(1).Item(2).ToString()

Resources