Tag: uri

图像源UriKind

我有一个项目,它的名字是’xx’。 我创建了一个具有此路径的文件夹“images”:xx \ bin \ Debug \ images \ 图像只包含一张照片,其名称为“1.jpg”,MainWindow包含图像控件; 我设置此代码加载图像源但它不起作用为什么??: private void Image_MouseDown(object sender, MouseButtonEventArgs e) { Image i = sender as Image; ; BitmapImage b = new BitmapImage(new Uri(@”images\1.jpg”,UriKind.Relative)); i.Source=b; } 如何通过代码加载图像源? 提前致谢 :)

我可以阻止Uri在WebRequest.Create中取消编码吗?

代码本身并不复杂,它只是不能正常工作: Uri uri = new Uri(“https://www.google.com/webmasters/tools/feeds/sites/http%3A%2F%2Fwww.mydomain.co.uk%2F”); WebRequest.Create(uri); 我从服务器上得到一个“错误请求”,经过多次挖掘,发现Uri正在变成 https://www.google.com/webmasters/tools/feeds/sites/http%3A//www.mydomain.co.uk/ 这不是我要求的,所以它有一个问题 有办法阻止这个吗?

为什么我的Stream不可读?

这是我的问题的续集,关于修剪日志文件中的脂肪。 我有这个代码: private readonly FileStream _fileStream; private readonly StreamWriter _streamWriter; . . . const int MAX_LINES_DESIRED = 1000; string uriPath = GetExecutionFolder() + “\\Application.log”; string localPath = new Uri(uriPath).LocalPath; if (!File.Exists(localPath)) { File.Create(localPath); } _fileStream = File.OpenWrite(localPath); // First, remove the earliest lines from the file if it’s grown too much StreamReader reader = new […]

为什么Uri对不同的方案表现不同?

在与Uriclass级一起回答另一个问题时,我发现了一些对我来说很奇怪的东西: 考虑这两个Uris: var u1 = new Uri(“http://ab:33/abc%2fdef/c?d=f”); var u2 = new Uri(“foobar://ab:33/abc%2fdef/c?d=f”); 它们的区别仅在于他们的计划。 提供的标识符的所有其他元素都是相同的。 那么,为什么当我转储这些Uri实例的Segments属性时,我是否会看到u1的以下输出: / ABC / 高清/ C …但u2输出不同? / ABC%2fdef / C 为什么不同方案的解析行为不同?

为什么Uri中的冒号“:”传递给Uri.MakeRelativeUri导致exception?

以下代码行给出了一个例外。 这是框架中的错误吗? 如果不是我可以采取什么方法呢? 它似乎是问题导致的“:”(冒号),但是我确实看到这样一个URI在生产网站上工作正常(即在现实世界中似乎是一个有效的URI) Uri relativeUri = new Uri(“http://test.com/asdf”).MakeRelativeUri(new Uri(“http://test.com/xx:yy”)); // gives => System.UriFormatException: A relative URI cannot be created because the // ‘uriString’ parameter represents an absolute URI Uri relativeUri = new Uri(“http://test.com/asdf”).MakeRelativeUri(new Uri(“http://test.com/xxyy”)); // this works – removed the colon between the xx and yy PS。 具体来说,鉴于以上情况,我可以问一下,我可以使用什么.NET类/方法(注意我正在从Web解析HTML页面)来获取(a)页面URI和(b)HTML中的相对字符串HREF参数[例如,在这种情况下可能是“/ xx:yy”]并返回可用于寻址该资源的有效URI? 换句话说,我如何模仿浏览器的行为,该浏览器转换HREF和页面URI以生成用于在单击它时转到该资源的URI。

与dontEscape的Uri构造函数已经过时,什么是交替?

我的问题是关于在没有转义的情况下将URL传递给HttpWebRequest,我搜索了论坛和互联网,但我找不到一个好的解决方案。 我有以下url: string URL= www.website.com/sub/redirec\t\bs\dd 所以,当我创建这样的uri时: Uri uri = new Uri(URL); HttpWebRequest request = (HttpWebRequest) WebRequest.Create(uri); 在这种情况下,我将获得以下URL: www.website.com/sub/redirect%5Ct%5Cbc%5Cdd 此符号“\”将替换为“%5C”。 什么对我不至关重要? 我可以通过以下方式避免: Uri uri = new Uri(URL, true); //bool dontEscape 但是这个构造函数已经过时了。 如何在不使用过时的情况下获得同样的效果?

对于任何字符串值,Uri.TryCreate都返回true?

我正在尝试使用Uri.TryCreate方法validationUri,当我使用无效字符串调用它时,该方法返回true。 有什么想法吗? 我的代码如下: private void button1_Click(object sender, EventArgs e) { Uri tempValue; if (Uri.TryCreate(“NotAURL”, UriKind.RelativeOrAbsolute, out tempValue)) { MessageBox.Show(“?”); } }

将文件上载到文件服务器

使用下面的链接,我为我的应用程序编写了一个代码。 我无法做到正确,请参考链接并帮助我使用它… 使用webclient类将文件上载到文件服务器 以下是我的代码: – protected void Button1_Click(object sender, EventArgs e) { filePath = FileUpload1.FileName; try { WebClient client = new WebClient(); NetworkCredential nc = new NetworkCredential(uName, password); Uri addy = new Uri(“\\\\192.168.1.3\\upload\\”); client.Credentials = nc; byte[] arrReturn = client.UploadFile(addy, filePath); Console.WriteLine(arrReturn.ToString()); } catch (Exception ex) { Console.WriteLine(ex.Message); } } 我还使用过: – File.Copy(filePath,“\\ 192.168.1.3 \ […]

我如何在媒体播放器中使用包uri资源?

我有一些非常简单的代码,只需要播放指定音量的声音,如下所示: var mp = new MediaPlayer(); mp.Open(uri); mp.Volume = volume; mp.Play(); 问题出现是因为这是Prism模块的一部分。 我不知道执行程序集将在哪里,所以我不能使用相对Uri或siteoforigin,MediaPlayer不理解包Uri语法。 我在程序集的根目录下有一个名为“notify.wav”的资源wav文件,但我无法通过Uri将其传递给MediaPlayer,并且无法通过任何其他方式加载它。 我该如何播放文件?

Application.GetContentStream为内容Uri返回null

我在项目集中将“sample.xml”文件作为内容。 我正在运行此代码: Uri uri = new Uri(“/sample.xml”, UriKind.Relative); StreamResourceInfo contentStream = Application.GetContentStream(uri); 为什么它返回null contentStream?