小编Gee*_*eth的帖子

从.NET/C#站点下载图像

我想从网站下载图像.我正在使用的代码在图像可用时工作正常.如果图像不可用则会产生问题.如何验证图像的可用性?

码:

方法1:

WebRequest requestPic = WebRequest.Create(imageUrl);

WebResponse responsePic = requestPic.GetResponse();

Image webImage = Image.FromStream(responsePic.GetResponseStream()); // Error

webImage.Save("D:\\Images\\Book\\" + fileName + ".jpg");
Run Code Online (Sandbox Code Playgroud)

方法2:

WebClient client = new WebClient();
Stream stream = client.OpenRead(imageUrl);

bitmap = new Bitmap(stream); // Error : Parameter is not valid.
stream.Flush();
stream.Close();
client.dispose();

if (bitmap != null)
{
    bitmap.Save("D:\\Images\\" + fileName + ".jpg");
}
Run Code Online (Sandbox Code Playgroud)

编辑:

Stream有以下声明:

      Length  '((System.Net.ConnectStream)(str)).Length' threw an exception of type  'System.NotSupportedException'    long {System.NotSupportedException}
    Position  '((System.Net.ConnectStream)(str)).Position' threw an exception of type 'System.NotSupportedException'    long {System.NotSupportedException}
 ReadTimeout …
Run Code Online (Sandbox Code Playgroud)

.net c# streaming image

62
推荐指数
3
解决办法
14万
查看次数

如何使用jquery获取上一页的URL

如何使用jquery获取上一页的URL?

我使用以下代码来获取当前页面位置

$(document).ready(function() {
var pathname = window.location.pathname;
});
Run Code Online (Sandbox Code Playgroud)

jquery

37
推荐指数
4
解决办法
12万
查看次数

如何隐藏WPF页面中的导航栏

我想在使用WPF创建的页面中隐藏导航栏.我试过了ShowsNavigationUI = false,但它仍然显示控件.

wpf xaml uinavigationbar

36
推荐指数
5
解决办法
5万
查看次数

如何在FileUpload控件中限制文件类型

是否可以允许fileupload控件只显示图像?

当我们单击"浏览"按钮时,它应该只显示图像.

c# asp.net file-upload image

26
推荐指数
4
解决办法
8万
查看次数

如何将XML从C#传递到SQL Server 2008中的存储过程?

我想将xml文件传递给sql server存储过程,如下所示:

CREATE PROCEDURE BookDetails_Insert (@xml xml)
Run Code Online (Sandbox Code Playgroud)

我想比较一些字段数据与其他表数据,如果匹配,则必须将记录插入到表中.

要求:

  1. 如何将XML传递给存储过程?我试过这个,但它不起作用:[工作]

    command.Parameters.Add(
        new SqlParameter("@xml", SqlDbType.Xml)
        {
            Value = new SqlXml(new XmlTextReader(xmlToSave.InnerXml,
                               XmlNodeType.Document, null))
        });
    
    Run Code Online (Sandbox Code Playgroud)
  2. 如何访问存储过程中的XML数据?

编辑:[工作]

 String sql = "BookDetails_Insert";
        XmlDocument xmlToSave = new XmlDocument();
        xmlToSave.Load("C:\\Documents and Settings\\Desktop\\XML_Report\\Books_1.xml");

        SqlConnection sqlCon = new SqlConnection("...");
        using (DbCommand command = sqlCon.CreateCommand())
        {
            **command.CommandType = CommandType.StoredProcedure;**
            command.CommandText = sql;
            command.Parameters.Add(
              new SqlParameter("@xml", SqlDbType.Xml)
              {
                  Value = new SqlXml(new XmlTextReader(xmlToSave.InnerXml
                             , XmlNodeType.Document, null))
              });

            sqlCon.Open();
            DbTransaction trans = sqlCon.BeginTransaction();
            command.Transaction = trans;

            try
            { …
Run Code Online (Sandbox Code Playgroud)

c# xml sql-server stored-procedures sqlparameter

25
推荐指数
1
解决办法
6万
查看次数

使用Linq获取列表<>的项目计数

我想查询List <>并找出MANY项如何与选择条件匹配.使用LINQ和c#/.net 3.5.如何修改查询以返回int计数.

var specialBook = from n in StoreDisplayTypeList 
                  where n.DisplayType=="Special Book" 
                  select n;
Run Code Online (Sandbox Code Playgroud)

c# linq asp.net-3.5

17
推荐指数
3
解决办法
6万
查看次数

如何使用JQuery获取div中的第一个子id

如何使用JQuery获取div中的第一个子id.

示例代码:

<div id='id1'>
    <a id='a1' />   
    <a id='a2' /> 
    <a id='a3' /> 
</div>
Run Code Online (Sandbox Code Playgroud)

我想得到身份证明a1.

我试图$('#id1 a:first-child').html()得到文本.如何获得身份证?

jquery dom

13
推荐指数
4
解决办法
7万
查看次数

文本框中的扫描值(使用扫描仪)

我正在使用Scanner(基本型号)来扫描条形码.扫描的条形码将在文本框中捕获.在txtBarcode_TextChanged事件中,我正在获取要访问的条形码.

问题:

如果我多次点击扫描仪,条形码会附加前一个值.

码:

 protected void txtBarcode_TextChanged(object sender, EventArgs e)
    {
        string txt = this.txtBarcode.Text;
        this.txtBarcode.Text = string.Empty;
    }
Run Code Online (Sandbox Code Playgroud)

javascript c# jquery web-applications barcode-scanner

11
推荐指数
1
解决办法
2万
查看次数

wpf - 从App Config文件中获取值

如何从App.Config获取值.

码:

 <configuration>
  <appSettings>
   <add key="ShowRoomCode" value="1000"/>
   <add key="FolderPath" value="D:\\Images\\Book\\"/>
  </appSettings>
 </configuration>

 string imageFolderPath = ConfigurationManager.AppSettings["FolderPath"];
Run Code Online (Sandbox Code Playgroud)

但它返回null值.配置文件位于同一项目中.

wpf configurationmanager appsettings

7
推荐指数
1
解决办法
2万
查看次数

Powershell脚本中的ExecuteReader()

我正在尝试从PowerShell脚本中读取SQL表中的数据.我可以在reader对象中看到数据,但是在使用While (readerobject.read()){}它时,它不会进入循环内部.

Powershell:

 $cmd = $sqlConn.CreateCommand()
 $cmd.CommandText ="SELECT * from user"
 $movedUserDetails = $cmd.ExecuteReader()
 while ($movedUserDetails.Read())
   {
      "[0] : " + $movedUserDetails.GetValue(0)
   }
 $movedUserDetails.Close() 
Run Code Online (Sandbox Code Playgroud)

sql powershell ado.net executereader

7
推荐指数
2
解决办法
3万
查看次数