Загрузка изображения на сайт - C#
Формулировка задачи:
Пишу программу по автоматическому заполнению формы сайта. Столкнулся с проблемой загрузкой изображений через iFrame. Не могу понять как загрузить изображение на сайт?
Подскажите, пожалуйста, как это делается c iFrame? Заранее, большое спасибо!
сайт: http://photodoska.ru/index.php?c=1&content=add_ads
<div id="add_photo_1" class="float_left add_photo" style="position:relative; border:none; width:134px; height:136px; border: none; margin-bottom:10px; margin-right:9px; ">
<div id="plus_photo_1" class="contaner" style="font-size:120px; display:block; color:#e6e6e6; position:absolute; top:5px; left:35px;">
+
</div>
<div class="upload">
[B]<iframe style="display: none;" id="frame_photo_1" name="frame_photo_1"></iframe>[/B]
<form id="upload_photo_1" method="post" enctype="multipart/form-data" action="/index.php?action=upload_photo" target="frame_photo_1">
<input type="hidden" name="date" value="22-03-15">
<input id="input_upload_photo_1" class="upload_photo" type="file" style="display: block !important; width: 135px !important; height: 136px !important; cursor:pointer; opacity: 0 !important; overflow: hidden !important;" name="upload">
</form>
</div>
</div>
Решение задачи: «Загрузка изображения на сайт»
textual
Листинг программы
private void tsbFill_Click(object sender, EventArgs e)
{
while (webBrowser1.ReadyState != WebBrowserReadyState.Complete)
Application.DoEvents();
for (int i = 0; i < countImage; i++)
{
_tagImage = "";
_fileNameImage = fileName;
if (_fileNameImage != "")
{
_tagImage = "input_upload_photo_" + (i + 1).ToString();
Populate().ContinueWith((_) =>
{
//...
}, TaskScheduler.FromCurrentSynchronizationContext());
}
}
}
async Task PopulateInputFile(HtmlElement file)
{
file.Focus();
// delay the execution of SendKey to let the Choose File dialog show up
var sendKeyTask = Task.Delay(1000).ContinueWith((_) =>
{
// this gets executed when the dialog is visible
SendKeys.Send(_fileNameImage + "{ENTER}");
}, TaskScheduler.FromCurrentSynchronizationContext());
file.InvokeMember("Click"); // this shows up the dialog
await sendKeyTask;
// delay continuation to let the Choose File dialog hide
await Task.Delay(1000);
}
async Task Populate()
{
var elements = webBrowser1.Document.GetElementsByTagName("input");
foreach (HtmlElement file in elements)
{
if (file.GetAttribute("id") == _tagImage)
{
file.Focus();
await PopulateInputFile(file);
}
}
}