interface ICoreWebView2ExperimentalFile
Note
This reference is no longer being maintained. For the latest API reference, see WebView2 API Reference.
Note
This an experimental API that is shipped with our prerelease SDK. See WebView2 release notes.
interface ICoreWebView2ExperimentalFile
: public IUnknown
Representation of a DOM File object passed via WebMessage.
Summary
Members | Descriptions |
---|---|
get_Path | Get the absolute file path. |
You can use this object to obtain the path of a File dropped on WebView2.
CHECK_FAILURE(m_webView->add_WebMessageReceived(
Callback<ICoreWebView2WebMessageReceivedEventHandler>(
[this](ICoreWebView2* sender, ICoreWebView2WebMessageReceivedEventArgs* args)
{
wil::com_ptr<ICoreWebView2ExperimentalWebMessageReceivedEventArgs> args2 =
wil::com_ptr<ICoreWebView2WebMessageReceivedEventArgs>(args)
.query<ICoreWebView2ExperimentalWebMessageReceivedEventArgs>();
wil::com_ptr<ICoreWebView2ExperimentalObjectCollectionView> objectsCollection;
args2->get_AdditionalObjects(&objectsCollection);
unsigned int length;
objectsCollection->get_Count(&length);
// Array of file paths to be sent back to the webview as JSON
std::wstring pathObjects = L"[";
for (unsigned int i = 0; i < length; i++)
{
wil::com_ptr<IUnknown> object;
objectsCollection->GetValueAtIndex(i, &object);
wil::com_ptr<ICoreWebView2ExperimentalFile> file =
object.query<ICoreWebView2ExperimentalFile>();
if (file)
{
// Add the file to message to be sent back to webview
wil::unique_cotaskmem_string path;
file->get_Path(&path);
std::wstring pathObject =
L"{\"path\":\"" + std::wstring(path.get()) + L"\"}";
// Escape backslashes
std::wstring pathObjectEscaped;
for (const auto& c : pathObject)
{
if (c == L'\\')
{
pathObjectEscaped += L"\\\\";
}
else
{
pathObjectEscaped += c;
}
}
pathObjects += pathObjectEscaped;
if (i < length - 1)
{
pathObjects += L",";
}
}
}
pathObjects += L"]";
// Post the message back to the webview so path is accessible to content
m_webView->PostWebMessageAsJson(pathObjects.c_str());
return S_OK;
})
.Get(),
&m_webMessageReceivedToken));
Applies to
Product | Introduced |
---|---|
WebView2 Win32 | N/A |
WebView2 Win32 Prerelease | 1.0.1671 |
Members
get_Path
Get the absolute file path.
public HRESULT get_Path(LPWSTR * path)