我正在加载图像如下
XAML
<Image Stretch="None" Grid.Row="16" Height="70" HorizontalAlignment="Left" Name="imgThumbnail" VerticalAlignment="Top" Width="70" Grid.RowSpan="3" Margin="133,1,0,0" Grid.Column="2" Grid.ColumnSpan="2" />
Run Code Online (Sandbox Code Playgroud)
代码隐藏
if (Path.GetFileNameWithoutExtension(filePath).ToLower().Contains(slugName.ToLower() + "_70x70"))
{
imgThumbnail.BeginInit();
imgThumbnail.Stretch = Stretch.UniformToFill;
imgThumbnail.Source = new BitmapImage(new Uri(filePath));
imgThumbnail.EndInit();
count = count + 1;
}
Run Code Online (Sandbox Code Playgroud)
上面的代码工作正常,现在我的缩略图旁边有一个删除按钮,如果删除按钮,我想删除源位置的所有图像.
这是删除图像文件的代码
internal int Remove(string slugName, DirectoryInfo outputFolder)
{
Helper.MetadataView.imgThumbnail.Source = null;
foreach (string filePath_ToBeDeleted in filePathList_ToBeDeleted)
{
if (File.Exists(filePath_ToBeDeleted))
{
Helper.MetadataView.imgThumbnail.IsEnabled = false;
File.Delete(filePath_ToBeDeleted);
count += 1;
}
}
return count;
}
return 0; // slugName == null
}
Run Code Online (Sandbox Code Playgroud)
我试图将源为null并删除,但它会抛出异常,如下所示
该进程无法访问文件'\ serv1\Dev\Images\730_Test4_0406_70x70.jpg',因为它正由另一个进程使用. …
我坚持在WPF中从我的文件位置加载图像.
这是我的xaml
<Image Grid.ColumnSpan="3" Grid.Row="11" Height="14" HorizontalAlignment="Left" Margin="57,1,0,0" Name="image1" Stretch="Fill" VerticalAlignment="Top" Width="108" />
Run Code Online (Sandbox Code Playgroud)
这是我背后的代码
internal int FindImages(string slugName, DirectoryInfo outputFolder)
{
if (slugName != null)
{
List<string> filePathList = Directory.GetFiles(outputFolder.FullName).ToList();
List<string> filePathList_ToBeDeleted = new List<string>();
foreach (string filePath in filePathList)
{
if (Path.GetFileNameWithoutExtension(filePath).ToLower().Contains("_70x70"))
{
image1.Source = filePath;
}
}
int count = 0;
return count;
}
Run Code Online (Sandbox Code Playgroud)
我的文件路径显示为 "\\\\Server1\\Dev\\Online\\Images\\7PMa_Test3_0306_70x70.jpg"
我在我的代码中使用Log4Net,它在我的进程运行时开始抛出这个奇怪的异常.
这是我对Log4Net的Appconfig,仍然不确定这里缺少什么
它像是一样
log4net:错误XmlHierarchyConfigurator:找不到属性[maxSizeRollBackups]来设置[log4net.Appender.FileAppender]上的对象.
配置:
<appender name="ErrorAppender" type="log4net.Appender.FileAppender,log4net">
<appendToFile value="true" />
<maxSizeRollBackups value="30" />
<maximumFileSize value="5MB" />
<rollingStyle value="Size" />
<staticLogFileName value="false" />
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
<file value="C:\Error.log"/>
<param name="AppendToFile" value="true"/>
<filter type="log4net.Filter.LevelRangeFilter">
<param name="LevelMin" value="ERROR"/>
<param name="LevelMax" value="ERROR"/>
</filter>
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-2p %c %method - %m%n"/>
</layout>
</appender>
Run Code Online (Sandbox Code Playgroud) ComboBox我的wpf应用程序中有一个静态,加载空格后跟0-9.我有以下代码它可以完成我需要的工作,但我觉得这不是一个好方法.任何建议或意见将不胜感激.
Test.xaml
<ComboBox Name="cbImportance"
Text="{Binding SelectedStory.ImportanceList, UpdateSourceTrigger=PropertyChanged, ValidatesOnExceptions=True, NotifyOnValidationError=True, ValidatesOnDataErrors=True}" Validation.ErrorTemplate="{StaticResource ErrorTemplate}"
Loaded="cbImportance_Loaded"
Grid.Column="1"
d:LayoutOverrides="Height"
Grid.ColumnSpan="2"
HorizontalAlignment="Stretch"
Margin="0,9"
SelectionChanged="cbImportance_SelectionChanged" />
Run Code Online (Sandbox Code Playgroud)
Test.xaml.cs
private void cbImportance_Loaded(object sender, RoutedEventArgs e)
{
List<string> data = new List<string>();
data.Add("");
data.Add("0");
data.Add("1");
data.Add("2");
data.Add("3");
data.Add("4");
data.Add("5");
data.Add("6");
data.Add("7");
data.Add("8");
data.Add("9");
// ... Get the ComboBox reference.
var cbImportance = sender as ComboBox;
// ... Assign the ItemsSource to the List.
cbImportance.ItemsSource = data;
// ... Make the first item selected.
cbImportance.SelectedIndex = 0;
}
Run Code Online (Sandbox Code Playgroud)
哪一个是加载静态值的有效方法 …
我只是试图传递一些值,但它总是抛出一个错误.有人可以纠正我在这里缺少的东西吗?
我在这里得到错误
Thread t_PerthOut = new Thread(new ThreadStart(ReadCentralOutQueue("test"));
Run Code Online (Sandbox Code Playgroud)
我想将此字符串值传递给ReadCentralOutQueue.
class Program
{
public void Main(string[] args)
{
Thread t_PerthOut = new Thread(new ThreadStart(ReadCentralOutQueue("test"));
t_PerthOut.Start();
}
public void ReadCentralOutQueue(string strQueueName)
{
System.Messaging.MessageQueue mq;
System.Messaging.Message mes;
string m;
while (true)
{
try
{
}
else
{
Console.WriteLine("Waiting for " + strQueueName + " Queue.....");
}
}
}
catch
{
m = "Exception Occured.";
Console.WriteLine(m);
}
finally
{
//Console.ReadLine();
}
}
}
}
Run Code Online (Sandbox Code Playgroud) 可能重复:
使用Sql Server 2008更改通知
我只是想知道无论如何我可以在C#中编写一个Windows服务,当新记录插入数据库时将触发该服务.
我想通过wcf连接DB.请提出任何想法或建议.
提前致谢.
基于demo.b指令,这是代码.
SQL数据库细节
我的数据库名称:MyWeb,表名称:StoryItems,列:位置,标题,名称,类型.
public partial class Triggers
{
// Enter existing table or view for the target and uncomment the attribute line
[Microsoft.SqlServer.Server.SqlTrigger(Name = "Trigger_Web", Target = "StoryItems", Event = "FOR INSERT")]
public static void Trigger_Web()
{
SqlCommand command;
SqlTriggerContext triggerContext = SqlContext.TriggerContext;
SqlPipe pipe = SqlContext.Pipe;
SqlDataReader reader;
if (triggerContext.TriggerAction == TriggerAction.Insert)
{
using (SqlConnection connection = new SqlConnection(@"context connection=true"))
{
connection.Open();
command = new SqlCommand(@"SELECT * FROM StoryItems", connection);
reader = …Run Code Online (Sandbox Code Playgroud) 感谢早先建议使用"XMLWriter",每次创建新的xml文件,所以我使用xmldoc加载xml文件然后追加到该文件中,这是我的代码,但它抛出异常说"这个文档已经有'DocumentElement'节点."
//Append to xml file
XmlDocument doc = new XmlDocument();
doc.Load(@"c:\\test.xml");
using (XmlWriter xmlWrite = doc.CreateNavigator().AppendChild())
{
xmlWrite.WriteStartElement("image name=",Name);
xmlWrite.WriteElementString("width", widthValue[1]);
xmlWrite.WriteElementString("Height", heightValue[1]);
xmlWrite.WriteElementString("file-size", FileSizeValue[1]);
xmlWrite.WriteElementString("file-format", FileFormatValue[1]);
xmlWrite.WriteElementString("resolution", ResolutionValue[1]);
xmlWrite.Close();
}
Run Code Online (Sandbox Code Playgroud)
这是我的示例test.xml
<job-metadata>
<slug>730s_Sales/CupWinner_0111</slug>
<locations>Africa</locations>
<primary-location>Africa</primary-location>
<reporter>Leigh Sales</reporter>
<genre>Current</genre>
<copyright>CBS</copyright>
<autopublish>true</autopublish>
</job-metadata>
Run Code Online (Sandbox Code Playgroud)
我试图像下面的xml一样追加
<job-metadata>
<slug>730s_Sales/CupWinner_0111</slug>
<locations>Africa</locations>
<primary-location>Africa</primary-location>
<reporter>Leigh Sales</reporter>
<genre>Current</genre>
<copyright>CBS</copyright>
<autopublish>true</autopublish>
<image name="557684_20111101-730s_SalesCupWinner_0111_80x60.jpg">
<width>80</width>
<height>60</height>
<file-size>7045</file-size>
<file-format>JPEG Baseline</file-format>
<resolution>72</resolution>
<custom-name>newsthumbnail</custom-name>
</image>
</job-metadata>
Run Code Online (Sandbox Code Playgroud)
提前致谢
我正在使用下面的代码上传我的文件,它工作正常,但有时它会抛出此错误“底层连接已关闭:服务器违反了协议”并停止该过程,当我再次运行它时,它上传文件没有任何问题。
我注意到一件事,如果我运行这个过程来上传多个文件,那么有时我会收到此错误,如果我上传的文件少于 5 个,那么它工作正常,知道我必须在哪里以及什么内容中查看它。
我在谷歌上搜索没有找到解决这个问题的可靠解决方案,甚至有一个 msdn 博客说它是 FTPwebrequest 中的一个错误,但不确定。
环境:C# 4.0,IIS FTP 服务器。
提前致谢
FileInfo fileInf = new FileInfo(filename);
FtpWebRequest reqFTP;
// Create FtpWebRequest object from the Uri provided
reqFTP = (FtpWebRequest)FtpWebRequest.Create
(new Uri(path + fileInf.Name));
// Provide the WebPermission Credintials
reqFTP.Credentials = new NetworkCredential(user, pwd);
// By default KeepAlive is true, where the control connection
// is not closed after a command is executed.
reqFTP.KeepAlive = false;
// Specify the command to be executed.
reqFTP.Method = WebRequestMethods.Ftp.UploadFile;
// Specify …Run Code Online (Sandbox Code Playgroud) 我有以下查询来选择记录,但我想格式化结果集上的列.
SELECT
COALESCE(dbo.tblMitchellLandscapeID.PatchSize,0) as PatchSize,
dbo.tblMitchellLandscape.MitchellLandscapeName
FROM tblMitchellLandscapeID
INNER JOIN dbo.tblMitchellLandscape
ON dbo.tblMitchellLandscapeID.MitchellLandscapeID=dbo.tblMitchellLandscape.MitchellLandscapeID
WHERE AssessmentVersionID = @AssessmentVersionID
Run Code Online (Sandbox Code Playgroud)
"PatchSize"是一个十进制值,因此它总是存储为两位小数"15.10".所有我试图在执行select语句时格式化为一个小数我想填充结果集,如"15.1"而不是15.10.
我创建了ac#库文件,它将转到本地路径,例如(c:\ test.txt)找到文件并上传到ftp服务器.
为了测试我只是从控制台应用程序调用dll,但我如何作为Windows服务运行,这将持续运行?
我想运行这个dll作为服务来监视c:\文件夹,如果任何文件像"test.txt"那样上传.
提前致谢