DoboWiki
Top
> 自由区/Webサービス紹介/Yahoo! Search Web Services/Image Searchコード(C#) をテンプレートにして作成
自由区/Webサービス紹介/Yahoo! Search Web Services/Image Searchコード(C#) をテンプレートにして作成
開始行:
*Yahoo! Image Search Web Services サンプルコード(C#) [#pd...
以下のコードを実行するには、xsd.exeで生成されたクラスが必...
#attach(noform)
#code(csharp){{
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional...
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Button1_Click(object sender, EventArgs...
{
string requestUrl =
"http://api.search.yahoo.com/ImageSearchServi...
requestUrl += "?appid=XXXXX";
requestUrl += "&query=" + HttpUtility.UrlEncode(T...
//検索の種類
if (searchType.SelectedValue != "" && searchType....
requestUrl += "&type=" + searchType.SelectedV...
//表示件数
if (resultsCount.SelectedValue != "" && resultsCo...
requestUrl += "&results=" + resultsCount.Sele...
//開始位置
//requestUrl += "&start=" + "1";
//検索するファイルの種類
if (fileFormat.SelectedValue != "" && fileFormat....
requestUrl += "&format=" + fileFormat.Selecte...
//カラーか白黒か
if (imageColor.SelectedValue != "" && imageColor....
requestUrl += "&coloration=" + imageColor.Sel...
//アダルトコンテンツを含める
if (adultOk.Checked)
requestUrl += "&adult_ok=1";
//検索するドメインを指定する
if (searchDomain.Text != "")
requestUrl += "&site=" + HttpUtility.UrlEncod...
System.Net.HttpWebRequest request =
(System.Net.HttpWebRequest)System.Net.WebRequ...
requestUrl);
System.Net.HttpWebResponse response = null;
Yahoo.us.ImageSearchResponse.ResultSet res;
try
{
response = (System.Net.HttpWebResponse)reques...
System.IO.Stream strm = response.GetResponseS...
System.Xml.Serialization.XmlSerializer serial...
new System.Xml.Serialization.XmlSerializer(
typeof(Yahoo.us.ImageSearchResponse.Resul...
res = (Yahoo.us.ImageSearchResponse.ResultSet)
serializer.Deserialize(strm);
}
catch (Exception ex)
{
Label1.Text = "エラー:" + ex.Message;
return;
}
finally
{
if (response != null)
response.Close();
}
//結果表示
Label1.Text = "";
Label1.Text += "<b>" + HttpUtility.HtmlEncode(Tex...
"</b> の検索結果 約 " +
res.totalResultsAvailable + "件中 " +
res.firstResultPosition + " - " +
res.totalResultsReturned + " 件目<br />\n";
if (res.Result != null)
{
Label1.Text += "<ul>\n";
foreach (Yahoo.us.ImageSearchResponse.ResultT...
{
Label1.Text += "<li><a href=\"" + item.Cl...
if (item.Thumbnail != null)
Label1.Text += "<img src=\"" + item.T...
Label1.Text += "<b>" + item.Title + "</b>...
Label1.Text += "<br />" + item.Width + "x...
"・" + item.FileSize + "byte";
Label1.Text += "<br /><a href=\"" + item....
"\">画像元ページへ</a>";
if (item.Summary != null && item.Summary....
Label1.Text += "<br />" + item.Summary;
if (item.Restrictions != null && item.Res...
Label1.Text += "<br />" + item.Restri...
}
Label1.Text += "</ul>\n";
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Yahoo! Image Search Web Services サンプル</tit...
</head>
<body>
<form id="form1" runat="server">
<div>
キーワード :
<asp:TextBox ID="TextBox1" runat="server"></asp:T...
<asp:Button ID="Button1" runat="server" OnClick="...
Text="画像検索" /><br />
キーワードを<asp:CheckBoxList ID="searchType" run...
RepeatDirection="Horizontal"
RepeatLayout="Flow">
<asp:ListItem Selected="True" Value="all">す...
</asp:ListItem>
<asp:ListItem Value="any">少なくとも1つ含む</...
<asp:ListItem Value="phrase">文章として含む</...
</asp:CheckBoxList><br />
表示件数 :
<asp:DropDownList ID="resultsCount" runat="server">
<asp:ListItem Value="10">10件</asp:ListItem>
<asp:ListItem Value="25">25件</asp:ListItem>
<asp:ListItem Value="50">50件</asp:ListItem>
</asp:DropDownList><br />
ファイル形式 :
<asp:DropDownList ID="fileFormat" runat="server">
<asp:ListItem Value="any">すべてのファイル形...
<asp:ListItem>bmp</asp:ListItem>
<asp:ListItem>gif</asp:ListItem>
<asp:ListItem>jpeg</asp:ListItem>
<asp:ListItem>png</asp:ListItem>
</asp:DropDownList><br />
画像の色 :
<asp:CheckBoxList ID="imageColor" runat="server"
RepeatDirection="Horizontal" RepeatLayout="Flow">
<asp:ListItem Selected="True" Value="any">す...
<asp:ListItem Value="color">カラー</asp:ListI...
<asp:ListItem Value="bw">白黒・グレースケール...
</asp:CheckBoxList><br />
<asp:CheckBox ID="adultOk" runat="server"
Text="アダルトコンテンツを含める" /><br />
ドメイン :
<asp:TextBox ID="searchDomain" runat="server">
</asp:TextBox><br />
<br />
<asp:Label ID="Label1" runat="server" EnableViewS...
</asp:Label>
<span style="color: #0000ff; text-decoration: und...
</div>
</form>
<!-- Begin Yahoo Web Services HTML Attribution Snippet -->
<a href="http://developer.yahoo.net/about/">
Web Services by Yahoo!
</a>
<!-- End Yahoo Web Services HTML Attribution Snippet -->
</body>
</html>
}}
//これより下は編集しないでください
#pageinfo(,2006-09-12 (火) 02:23:15,DOBON!,2006-09-12 (火...
終了行:
*Yahoo! Image Search Web Services サンプルコード(C#) [#pd...
以下のコードを実行するには、xsd.exeで生成されたクラスが必...
#attach(noform)
#code(csharp){{
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional...
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Button1_Click(object sender, EventArgs...
{
string requestUrl =
"http://api.search.yahoo.com/ImageSearchServi...
requestUrl += "?appid=XXXXX";
requestUrl += "&query=" + HttpUtility.UrlEncode(T...
//検索の種類
if (searchType.SelectedValue != "" && searchType....
requestUrl += "&type=" + searchType.SelectedV...
//表示件数
if (resultsCount.SelectedValue != "" && resultsCo...
requestUrl += "&results=" + resultsCount.Sele...
//開始位置
//requestUrl += "&start=" + "1";
//検索するファイルの種類
if (fileFormat.SelectedValue != "" && fileFormat....
requestUrl += "&format=" + fileFormat.Selecte...
//カラーか白黒か
if (imageColor.SelectedValue != "" && imageColor....
requestUrl += "&coloration=" + imageColor.Sel...
//アダルトコンテンツを含める
if (adultOk.Checked)
requestUrl += "&adult_ok=1";
//検索するドメインを指定する
if (searchDomain.Text != "")
requestUrl += "&site=" + HttpUtility.UrlEncod...
System.Net.HttpWebRequest request =
(System.Net.HttpWebRequest)System.Net.WebRequ...
requestUrl);
System.Net.HttpWebResponse response = null;
Yahoo.us.ImageSearchResponse.ResultSet res;
try
{
response = (System.Net.HttpWebResponse)reques...
System.IO.Stream strm = response.GetResponseS...
System.Xml.Serialization.XmlSerializer serial...
new System.Xml.Serialization.XmlSerializer(
typeof(Yahoo.us.ImageSearchResponse.Resul...
res = (Yahoo.us.ImageSearchResponse.ResultSet)
serializer.Deserialize(strm);
}
catch (Exception ex)
{
Label1.Text = "エラー:" + ex.Message;
return;
}
finally
{
if (response != null)
response.Close();
}
//結果表示
Label1.Text = "";
Label1.Text += "<b>" + HttpUtility.HtmlEncode(Tex...
"</b> の検索結果 約 " +
res.totalResultsAvailable + "件中 " +
res.firstResultPosition + " - " +
res.totalResultsReturned + " 件目<br />\n";
if (res.Result != null)
{
Label1.Text += "<ul>\n";
foreach (Yahoo.us.ImageSearchResponse.ResultT...
{
Label1.Text += "<li><a href=\"" + item.Cl...
if (item.Thumbnail != null)
Label1.Text += "<img src=\"" + item.T...
Label1.Text += "<b>" + item.Title + "</b>...
Label1.Text += "<br />" + item.Width + "x...
"・" + item.FileSize + "byte";
Label1.Text += "<br /><a href=\"" + item....
"\">画像元ページへ</a>";
if (item.Summary != null && item.Summary....
Label1.Text += "<br />" + item.Summary;
if (item.Restrictions != null && item.Res...
Label1.Text += "<br />" + item.Restri...
}
Label1.Text += "</ul>\n";
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Yahoo! Image Search Web Services サンプル</tit...
</head>
<body>
<form id="form1" runat="server">
<div>
キーワード :
<asp:TextBox ID="TextBox1" runat="server"></asp:T...
<asp:Button ID="Button1" runat="server" OnClick="...
Text="画像検索" /><br />
キーワードを<asp:CheckBoxList ID="searchType" run...
RepeatDirection="Horizontal"
RepeatLayout="Flow">
<asp:ListItem Selected="True" Value="all">す...
</asp:ListItem>
<asp:ListItem Value="any">少なくとも1つ含む</...
<asp:ListItem Value="phrase">文章として含む</...
</asp:CheckBoxList><br />
表示件数 :
<asp:DropDownList ID="resultsCount" runat="server">
<asp:ListItem Value="10">10件</asp:ListItem>
<asp:ListItem Value="25">25件</asp:ListItem>
<asp:ListItem Value="50">50件</asp:ListItem>
</asp:DropDownList><br />
ファイル形式 :
<asp:DropDownList ID="fileFormat" runat="server">
<asp:ListItem Value="any">すべてのファイル形...
<asp:ListItem>bmp</asp:ListItem>
<asp:ListItem>gif</asp:ListItem>
<asp:ListItem>jpeg</asp:ListItem>
<asp:ListItem>png</asp:ListItem>
</asp:DropDownList><br />
画像の色 :
<asp:CheckBoxList ID="imageColor" runat="server"
RepeatDirection="Horizontal" RepeatLayout="Flow">
<asp:ListItem Selected="True" Value="any">す...
<asp:ListItem Value="color">カラー</asp:ListI...
<asp:ListItem Value="bw">白黒・グレースケール...
</asp:CheckBoxList><br />
<asp:CheckBox ID="adultOk" runat="server"
Text="アダルトコンテンツを含める" /><br />
ドメイン :
<asp:TextBox ID="searchDomain" runat="server">
</asp:TextBox><br />
<br />
<asp:Label ID="Label1" runat="server" EnableViewS...
</asp:Label>
<span style="color: #0000ff; text-decoration: und...
</div>
</form>
<!-- Begin Yahoo Web Services HTML Attribution Snippet -->
<a href="http://developer.yahoo.net/about/">
Web Services by Yahoo!
</a>
<!-- End Yahoo Web Services HTML Attribution Snippet -->
</body>
</html>
}}
//これより下は編集しないでください
#pageinfo(,2006-09-12 (火) 02:23:15,DOBON!,2006-09-12 (火...
ページ名:
▲
▼
[
トップ
] [
新規
|
子ページ作成
|
一覧
|
単語検索
|
最終更新
|
ヘルプ
]