如何使用c#代码下载.zip文件格式?
这是代码,我用来下载.只是为了突出显示,如果我下载.txt文件,它工作正常.如果我下载.zip文件,它会下载.zip文件但我无法打开它.它抱怨.zip的格式不正确.我怀疑我如何在本地驱动器上写回文件.
救命?
string ftpServerIP = FTPServer;
string ftpUserID = FTPUser;
string ftpPassword = FTPPwd;
FileInfo fileInf = new FileInfo(FileName);
string uri = "ftp://" + ftpServerIP + "/" + fileInf.Name;
FtpWebRequest reqFTP = (FtpWebRequest)FtpWebRequest.Create(uri); //new Uri("ftp://" + ftpServerIP + DestinationFolder + fileInf.Name));
reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
reqFTP.EnableSsl = true;
reqFTP.KeepAlive = false;
reqFTP.UseBinary = true;
//reqFTP.UsePassive = true;
reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;
ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(AcceptAllCertifications);
//Stream strm = reqFTP.GetRequestStream();
StreamReader reader = new StreamReader(reqFTP.GetResponse().GetResponseStream());
StreamWriter writer = new StreamWriter(Path.Combine(FolderToWriteFiles, …Run Code Online (Sandbox Code Playgroud) 为什么这些查询会返回不同的值?第一个返回结果集按预期,但第二个(据我所知,完全相同)不会.有什么想法吗?
1:
declare @c varchar(200)
set @c = 'columnName'
select top 1 *
from myTable
where @c is not null
and len(convert(varchar, @c)) > 0
Run Code Online (Sandbox Code Playgroud)
2:
SELECT top 1 *
FROM myTable
WHERE columnName IS NOT NULL
and len(convert(varchar,columnName)) > 0
Run Code Online (Sandbox Code Playgroud) 我有一个专为iPhone OS 2.x设计的应用程序.
在某些时候我有这个代码
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//... previous stuff initializing the cell and the identifier
cell = [[[UITableViewCell alloc]
initWithFrame:CGRectZero
reuseIdentifier:myIdentifier] autorelease]; // A
// ... more stuff
}
Run Code Online (Sandbox Code Playgroud)
但由于initWithFrame选择器在3.0中已弃用,我需要使用respondToSelector和performSelector转换此代码......因此...
if ( [cell respondsToSelector:@selector(initWithFrame:)] ) { // iphone 2.0
// [cell performSelector:@selector(initWithFrame:) ... ???? what?
}
Run Code Online (Sandbox Code Playgroud)
我的问题是:如果我必须传递两个参数"initWithFrame:CGRectZero"和"reuseIdentifier:myIdentifier",我如何将A上的调用断开到preformSelector调用?
编辑 - 由于fbrereto的消化,我做到了这一点
[cell performSelector:@selector(initWithFrame:reuseIdentifier:)
withObject:CGRectZero
withObject:myIdentifier];
Run Code Online (Sandbox Code Playgroud)
我遇到的错误是"performSelector:withObject:withObject"的参数2的不兼容类型.
myIdentifier是这样声明的
static NSString *myIdentifier = @"Normal";
Run Code Online (Sandbox Code Playgroud)
我试图将呼叫改为
[cell performSelector:@selector(initWithFrame:reuseIdentifier:)
withObject:CGRectZero
withObject:[NSString stringWithString:myIdentifier]];
Run Code Online (Sandbox Code Playgroud)
没有成功...
另一点是CGRectZero不是一个对象......
我正在使用ObjectDataSource将数据绑定到GridView; 它工作正常,除了它总是创建一个新对象用作数据源.我可以很好地完成所有设置但我不能使用现有对象的实例来指定它作为"数据源".是否有可能做到这一点?如果是这样,怎么样?
如果不可能,为什么?
编辑:这是发生了什么的要点(对象类型已更改):在第一页上,您正在编辑狗的属性.其中一个属性是"有小狗",如果它是真的,下一页你指定那些小狗的名字.在我的情况下发生的事情是那些小狗没有与原始狗相关联,而是与"新"狗相关联.(我的问题是"母狗"的含义是巧合.;-))
我遇到了问题.我在页面中嵌入了WMP,我需要隐藏播放器中的按钮.我让它隐藏在IE和FF中,但我无法在谷歌浏览器中实现它.这是代码
<object id="MediaPlayer1" width="690" height="500" classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95"
codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701"
standby="Loading Microsoft® Windows® Media Player components..." type="application/x-oleobject"
>
<param name="FileName" value='<%= GetSource() %>' />
<param name="AutoStart" value="True" />
<param name="DefaultFrame" value="mainFrame" />
<param name="ShowStatusBar" value="0" />
<param name="ShowPositionControls" value="0" />
<param name="showcontrols" value="0" />
<param name="ShowAudioControls" value="0" />
<param name="ShowTracker" value="0" />
<param name="EnablePositionControls" value="0" />
<!-- BEGIN PLUG-IN HTML FOR FIREFOX-->
<embed type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/MediaPlayer/"
src='<%= GetSource() %>' align="middle" width="600" height="500" defaultframe="rightFrame"
id="MediaPlayer2" />
</object>
Run Code Online (Sandbox Code Playgroud)
在JS中我用的方法
var player = document.getElementById("MediaPlayer2");
player.uiMode="none";
Run Code Online (Sandbox Code Playgroud)
隐藏FF中的按钮,但似乎不适用于Chrome.
说我有两个清单:
let a = [1 .. 1000]
let b = [250 .. 500]
Run Code Online (Sandbox Code Playgroud)
如何获取包含值{1-249,501-1000}的新列表?
我正在研究处理从手机接收的请求的Web服务器应用程序.我有请求适配器,它适应我在应用程序其余部分使用的请求类中的电话请求.每个请求适配器的作用是它访问会话中的一个对象并更改其中一个属性.现在,问题是:我想编写一个测试此请求适配器的单元测试,但是在执行测试时我没有会话.有什么方法可以创建一个会话或类似的东西来测试完整的适配器?
提前致谢
我有一张表格,列出了每个班级的学生成绩。我想要一个如下所示的结果集:
BIO...B
CHEM...C
Run Code Online (Sandbox Code Playgroud)
其中“B”和“C”是该类的模式。我可以获得所有成绩的模式,但不确定如何获得每个班级的模式
我有一个验证方法,有许多条件语句.基本上就是这样
If Check1 = false
return false
If Check2 = false
return false
etc
Run Code Online (Sandbox Code Playgroud)
FxCop抱怨说圈复杂度太高了.我知道在函数中间使用return语句不是最佳实践,但与此同时,我看到的唯一替代方法是一个丑陋的If-else语句列表.解决这个问题的最佳方法是什么?
提前致谢.
我正处于循环数据并根据设置以特定方式对其进行格式化的情况,我担心我认为风格最佳可能会影响性能.
代码的基本模式如下
enum setting {single, multiple, foo, bar};
Data data = getData(Connection conn, int id);
setting blah = data.getSetting();
foreach (Item item in data)
{
switch(blah)
{
case blah.single:
processDataSingle(item blah);
break;
...
}
}
Run Code Online (Sandbox Code Playgroud)
我担心的是数据中可能有数千甚至数万项.我想知道是否在循环内部的开关可能会反复评估可能会导致一些严重的性能问题.我知道我可以把它放在switch循环之前,但是每个都case包含它,这似乎更不易读,因为基本功能保持不变是不太明显的.
c# ×3
sql ×2
.net ×1
asp.net-2.0 ×1
cocoa ×1
coding-style ×1
f# ×1
ftp ×1
fxcop ×1
ipad ×1
iphone ×1
performance ×1
refactoring ×1
sftp ×1
t-sql ×1
unit-testing ×1
wmp ×1