在C#中编写一些代码,我想知道是否有办法获取directoryinfo对象的正确路径?
例如,目前我有一个目录,例如:
DirectoryInfo dirInfo = new DirectoryInfo(pathToDirectory);
Run Code Online (Sandbox Code Playgroud)
问题是,如果我想获取该特定dirInfo对象的路径,它总是返回调试路径(bin文件夹).如果原始dirInfo对象引用D:\testDirectory路径中的目录,那么我想要一种方法在代码中的其他位置再次获取该路径而不是获取\bin\debug\testDirectory
有没有办法做到这一点?
目前我正在尝试使用以下方式获取dirInfo的路径Path:
Console.WriteLine("Path: " + Path.GetFullPath(dirInfo.ToString()));
Run Code Online (Sandbox Code Playgroud) 我正在制作一个可移植的C#类库,我正在尝试为我的项目添加一个Web服务引用.
使用VS 2013,我右键单击解决方案,在我的其他项目中,可以选择"添加服务引用".但在我的移动图书馆项目中,该选项不存在.
是否需要做一些特殊的事情来向移动库添加服务引用,或者这是不可能的?
看截图,甚至没有选项来为我的项目添加服务引用.

我试图在java中解压缩包含文件夹以及存档内的文件的存档.问题是,只要它到达文件夹并尝试解压缩它们就会抛出FNF异常.我的解压缩代码如下:
private void unZipUpdate(String pathToUpdateZip, String destinationPath){
byte[] byteBuffer = new byte[1024];
try{
ZipInputStream inZip = new ZipInputStream(new FileInputStream(pathToUpdateZip));
ZipEntry inZipEntry = inZip.getNextEntry();
while(inZipEntry != null){
String fileName = inZipEntry.getName();
File unZippedFile = new File(destinationPath + File.separator + fileName);
System.out.println("Unzipping: " + unZippedFile.getAbsoluteFile());
new File(unZippedFile.getParent()).mkdirs();
FileOutputStream unZippedFileOutputStream = new FileOutputStream(unZippedFile);
int length;
while((length = inZip.read(byteBuffer)) > 0){
unZippedFileOutputStream.write(byteBuffer,0,length);
}
unZippedFileOutputStream.close();
inZipEntry = inZip.getNextEntry();
}
inZipEntry.clone();
inZip.close();
System.out.println("Finished Unzipping");
}catch(IOException e){
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
我以为我有处理过的压缩文件夹
new File(unZippedFile.getParent()).mkdirs();
Run Code Online (Sandbox Code Playgroud)
但这似乎并未解决问题.我在这里错过了什么?
堆栈跟踪:
Unzipping: D:\UnzipTest\aspell …Run Code Online (Sandbox Code Playgroud) 我目前在Java中设置了一个项目,在Eclipse中使用以下目录结构:

在我的代码中,我有以下几行:
InputStream is = this.getClass().getClassLoader().getResourceAsStream("resources/config");
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(is));
Run Code Online (Sandbox Code Playgroud)
但是,InputStream is总是被赋值为null,这会在到达第二行时导致崩溃.我知道它与我如何设置它正在寻找的路径有关,但我无法弄清楚它为什么不起作用.
我遇到了JScrollPanes和JTextArea对象的问题,并让它们一起工作.
如果我只是将JTextArea添加到我的JPanel中,它可以正常工作并显示我告诉它的位置.但是,如果我将contentPane.add(textArea)更改为contentPane.add(new JScrollPane(textArea)),则textArea不再可见,并且没有textarea的迹象.
这是我的代码:
public docToolGUI() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 611, 487);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
textField = new JTextField();
textField.setBounds(253, 323, 86, 20);
contentPane.add(textField);
textField.setColumns(10);
JLabel lblEnterRootDirectory = new JLabel("Enter Root Directory");
lblEnterRootDirectory.setBounds(253, 293, 127, 20);
contentPane.add(lblEnterRootDirectory);
JButton btnGo = new JButton("Go");
btnGo.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
new ToolWorker().execute();
}
});
btnGo.setBounds(253, 361, 89, 23);
contentPane.add(btnGo);
textArea = new JTextArea();
textArea.setWrapStyleWord(true);
textArea.setEditable(false);
textArea.setBounds(25, 11, 560, 276);
contentPane.add(new JScrollPane(textArea)); …Run Code Online (Sandbox Code Playgroud) 我有一个UITableView的UISearchBar,实现如下:
-(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{
[self.searchBar becomeFirstResponder];
if(searchText.length == 0)
{
self.isFiltered = NO;
}
else
{
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF.writer1 contains[c] %@", searchText];
self.isFiltered = YES;
[[RTRepairOrderStore sharedStore] filterROArray:predicate];
}
[self.tableView reloadData];
}
Run Code Online (Sandbox Code Playgroud)
问题是,当我在搜索栏中输入一个字母后,搜索就可以了,但是键盘立即被关闭了。我该如何预防?
我试图让我的表单等到我的_Load方法的特定部分完成后再继续.我有一些异步的方法,但我无法弄清楚为什么我无法让代码等到fakeClickCheckUpdate完成后再继续.以下是涉及的主要方法:
public myForm(string args)
{
InitializeComponent();
Load += myForm_Load;
}
private void myForm_Load(object s, EventArgs e)
{
this.fakeClickCheckUpdate();
loadFinished = true;
if (this.needsUpdate == true)
{
Console.WriteLine("Needs update...");
}
else
{
Console.WriteLine("update is false");
}
}
public void fakeClickCheckUpdate()
{
this.checkUpdateButton.PerformClick();
}
private async void checkUpdateButton_Click(object sender, EventArgs e)
{
await startDownload(versionLink, versionSaveTo);
await checkVersion();
Console.WriteLine(needsUpdate);
}
private async Task checkVersion()
{
string currVersion;
string newVersion;
using (StreamReader sr = new StreamReader(currVersionTxt))
{
currVersion = sr.ReadToEnd(); …Run Code Online (Sandbox Code Playgroud) 我有一个自定义UITableViewCell类,我想用它来创建自定义表格单元格.我创建了自定义表格单元格的xib及其标题和实现文件,全部调用RTRepairOrderTableCell.m/.h/.xib.
我的问题是,即使我将表格单元格的重用标识符设置为RTRepairOrderTableCell.xib文件内部并在我的表视图控制器中注册了xib,我仍然在尝试出列或创建新单元格时出现断言错误使用.
在我的视图(表)控制器内部,我有以下内容:
- (void)viewDidLoad
{
[super viewDidLoad];
//Load the nib file
UINib *nib = [UINib nibWithNibName:@"RTRepairOrderTableCell"
bundle:nil];
// Register this Nib, which contains the cell
[self.tableView registerNib:nib
forCellReuseIdentifier:@"RTRepairOrderTableCell"];
}
Run Code Online (Sandbox Code Playgroud)
这里没有错误,它完成viewDidLoad得很好.
在我的内心cellForRowAtIndexPath我有以下内容:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
RTRepairOrderTableCell *cell = [tableView dequeueReusableCellWithIdentifier:@"RTRepairOrderTableCell" forIndexPath:indexPath];
return cell;
}
Run Code Online (Sandbox Code Playgroud)
根据我见过的每个教程,只要我在xib文件中正确设置了重用标识符并且我viewDidLoad在视图控制器类中注册了将显示表格单元格的xib,这应该可以工作,所以我在失去了我为什么得到
*** Assertion failure in -[UITableView _dequeueReusableViewOfType:withIdentifier:], /SourceCache/UIKit/UIKit-2935.138/UITableView.m:5413
Run Code Online (Sandbox Code Playgroud) 在项目中Visual Studio 2013使用时如何反序列化对象Add Service Reference?我问是因为我有以下课程:
public class RTMImagePackage
{
private int maxImages = 15;
[DataMember(EmitDefaultValue = false)]
public int MaxImages
{
get { return this.maxImages; }
private set { this.maxImages = value; }
}
[OnDeserialized]
void OnDeserialized(StreamingContext c)
{
if (maxImages == 0)
{
maxImages = 15;
}
}
}
Run Code Online (Sandbox Code Playgroud)
如果使用本地IIS,然后我自我主机创建一个单独的项目,并使用添加此WCF服务Add Service Reference的任何新的实例RTMImagePackage总是有一个MaxImages0值,即使我在多个地方将其设置为15,甚至里面开头用的方法OnDeserialized。
如果我加入一些断点,我可以看到该OnDeserialized方法甚至从未在 Web 服务端调用,即使我尝试使用适当的断点更新服务引用。
基本上我试图保证客户端将始终具有MaxImages当它产生的代理类设置为15 WITHOUT不必使用部分类。有没有明确的方法来做到这一点?我检查了其他答案,他们的方法是使用OnDeserializedorOnDeserializing但这似乎对我不起作用。
有小费吗?
c# ×4
java ×3
io ×2
.net ×1
ios ×1
jframe ×1
objective-c ×1
swing ×1
task ×1
uisearchbar ×1
uitableview ×1
wcf ×1
web-services ×1
xcode ×1
xib ×1