×
Namespaces

Variants
Actions

使用CDocumentHandler将内容拷贝到预先定义的目录中

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata

文章
hoolee 在 18 Aug 2008 创建
最后由 hamishwillee 在 15 Dec 2011 编辑

CS001053


设备, 软件 版本:

S60 3rd Edition, FP1


Contents

详细描述

特定类型的文件需放在特定的目录中,Document Handler API可以用来查找已经文件类型的正确存放位置,如图片或音频文件。下列代码演示了如何通过CDocumentHandler将内容拷贝到预先定义的适当目录中。


这个代码自签名即可执行。


MMP文件

需要下列链接库:

LIBRARY  apmime.lib    // TDataType
LIBRARY commonui.lib // CDocumentHandler


头文件

#include <DocumentHandler.h>private:  // Data
CDocumentHandler* iDocHandler;


源文件

#include <DocumentHandler.h>iDocHandler = CDocumentHandler::NewL(CEikonEnv::Static()->Process());// Source 
 
file.
_LIT(KSrcFile, "C:\\Data\\Others\\picture.jpg");
// Destination file. File extension is obtained from the source file.
_LIT(KDestFile, "destination");
 
TDataType nullType; // Explicit MIME type not set
TInt ret = KErrNone;
// Copy the source to the destination. The Document Handler API recognizes that
// the file is an image and copies it to the Gallery (C:\Data\Images directory
// in S60 3rd Edition). The function call also displays a notification to the
// user after copying is done.
TRAPD(err, ret = iDocHandler->CopyL(KSrcFile, KDestFile, nullType,
KEntryAttNormal));
 
if (err || ret)
{
// TODO: Error handling
}
 
// Get and display the destination path
TFileName path;
iDocHandler->GetPath(path);
CAknInformationNote* note = new (ELeave)CAknInformationNote(ETrue);
note->ExecuteLD(path);


后记

源文件C:\Data\Others\picture.jpg将会被拷贝到多媒体文件夹中,重命名为destination.jpg

This page was last modified on 15 December 2011, at 09:02.
63 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×