我有一个PDF,主题是http://test.com/mypdf.pdf.
如何将PDF转换为Stream然后使用此Stream转换回PDF.
我尝试了以下但有例外(见图):
private static Stream ConvertToStream(string fileUrl)
{
HttpWebResponse aResponse = null;
try
{
HttpWebRequest aRequest = (HttpWebRequest)WebRequest.Create(fileUrl);
aResponse = (HttpWebResponse)aRequest.GetResponse();
}
catch (Exception ex)
{
}
return aResponse.GetResponseStream();
}
Run Code Online (Sandbox Code Playgroud)

where如果字符串末尾有单词,我需要修剪字符串。C# 中对此执行快速的方法是什么?
注意:要修剪的词可以是任何东西..WHERE只是一个例子
string text1 = "My hosue where sun shines"; //RESULT: "My hosue where sun shines"
string text2 = "My where"; //RESULT: "My"
string text3 = "My where I WHERE"; //RESULT:"My where I"
Run Code Online (Sandbox Code Playgroud) 我使用HttpWebRequest,以POST通过Web服务的字节数组图片,图片大小是一样的东西byte[4096]
码:
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(wsHost);
webRequest.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip,deflate");
webRequest.Headers.Add(HttpRequestHeader.KeepAlive, "true");
Run Code Online (Sandbox Code Playgroud)
我收到一个错误:
The underlying connection was closed. A connection that was expected to be kept alive was closed by the server
Run Code Online (Sandbox Code Playgroud)
这是服务器问题,还是我的发布问题?
我需要在string中找到匹配的GUID Regex
string findGuid="hi sdkfj 1481de3f-281e-9902-f98b-31e9e422431f sdfsf 1481de3f-281e-9902-f98b-31e9e422431f"
var guid = Regex.Match(m.HtmlBody.TextData, @"^(\{){0,1}[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}(\}){0,1}$").Value;
Run Code Online (Sandbox Code Playgroud) 我正在尝试从a中删除所有空行TableLayoutPanel.到目前为止,我已经能够这样做了
private void RemoveEmptyRows()
{
for (int row = 0; row < tablePanel.RowCount - 1; row++)
{
bool hasControl = false;
for (int col = 0; col < tablePanel.ColumnCount; col++)
{
if (tablePanel.GetControlFromPosition(col, row) != null)
{
hasControl = true;
break;
}
}
if (!hasControl)
tablePanel.RowStyles.RemoveAt(row);
}
}
Run Code Online (Sandbox Code Playgroud)
有更好的方法吗?我的方法似乎太不堪重负了.
有一个 SortedList
slLanguage = new SortedList();
slLanguage.Add("Bahasa","id-ID");
slLanguage.Add("Chinese Simplified(????)","zh-CN");
slLanguage.Add("Chinese Traditional(????)","zh-TW");
slLanguage.Add("Kazakh","kk-KZ");
slLanguage.Add("Russian(???????)","ru-RU");
slLanguage.Add("Vietnamese(Vi?t)","vi-VN");
slLanguage.Add("English", "en-US");
Run Code Online (Sandbox Code Playgroud)
如何按价值获得密钥?
例如:获取项目键"zh-CN"
更具体地说,完整的错误是
../../Scripts/LuaTest.lua:1:'ï'附近的意外符号
我LuaTest.lua用不同的编辑器检查了文件,包括Notepad ++,找不到任何额外/隐藏的字符.我对可能导致这种情况的原因感到茫然.
旁注,我正在遵循本指南:Godpatterns:用C#编写Lua脚本
这是主要的代码块:
class Program
{
static void Main(string[] args)
{
Lua lua = new Lua();
Program program = new Program();
// register our C# functions
lua.RegisterFunction("DanSays", program, program.GetType().GetMethod("DanSays"));
lua.RegisterFunction("ThorSays", program, program.GetType().GetMethod("ThorSays"));
lua.DoFile("../../Scripts/LuaTest.lua");
Console.ReadLine();
}
public void DanSays(string s)
{
Console.WriteLine("Dan Says > " + s);
}
public void ThorSays(string s)
{
Console.WriteLine("Thor says > " + s);
}
}
Run Code Online (Sandbox Code Playgroud)
另外,这是 LuaTest.lua
DanSays("Hey, Thor!");
ThorSays("Hi Dan! You know Thursdays . . . ");
DanSays("*sigh* …Run Code Online (Sandbox Code Playgroud) DateTime todayDateTime = DateTime.Now;
StringBuilder todayDateTimeSB = new StringBuilder("0");
todayDateTimeSB.Append(todayDateTime.ToString("MMddyyyy"));
long todayDateTimeLongValue = Convert.ToInt64(todayDateTimeSB.ToString());
// convert to byte array packed decimal
byte[] packedDecValue = ToComp3UsingStrings(todayDateTimeLongValue);
// append each byte to the string builder
foreach (byte b in packedDecValue)
{
sb.Append(b); // bytes 56-60
}
sb.Append(' ', 37);
Run Code Online (Sandbox Code Playgroud)
上面的代码获取当前日期时间,将其格式化为long值并将其传递给将其转换为压缩十进制格式的方法.我知道上面的工作是因为当我逐步执行代码时,字节数组对于我期望的所有字节都具有正确的十六进制值.
但是上面是我遇到问题的代码,特别是我已经研究过,发现字符串生成器.Append(byte)实际上ToString()为该字节做了一个.当它将字节添加到字符串时,这会改变字节的值.问题是我如何告诉StringBuilder它按原样取出'byte'并将其存储在内存中而不格式化/改变值.我知道还有一个.AppendFormat()有几个重载使用它IFormatProvider来提供很多很多关于如何格式化的选项,但是我没有看到任何方法告诉它不格式化/改变/改变数据的值.
如何读取文件字节MemoryMappedFile并将其放入byte[]数组?
插入字符串时我需要检查和转义的字符是什么?
INSERT INTO gamedata (gamename, url, dlink)
VALUES ('mady's run', 'http://www.sdfa.com', 'http://extabit.com/sdf')</code>
Run Code Online (Sandbox Code Playgroud)
我该如何逃避这些角色?
我正在使用C#并使用SQL Server Management Studio 2008管理数据库.