LinqPad is handy# DotNet - 窗口里的风景
c*t
1 楼
http://www.linqpad.net/
It's not as heavy as VS; but very handy to test out code snippets. For an
exmple download music from wenxuecity.com. Once you figured out the
playListXml (either view source or sniff), a few lines code as follows run
great in LinqPad:
void Main()
{
string playListUrl = @"http://space.wenxuecity.com/media/1292261551.xml";
using(WebClient wc = new WebClient())
{
wc.Headers.Add("User-Agent", "Mozilla/4.0 (compatible; MSIE
8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .
NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; MS-RTC LM 8; .NET4.0C; .NET4.0E)"
);
string xmlContent = wc.DownloadString(playListUrl);
XDocument doc = XDocument.Parse(xmlContent);
foreach(var s in doc.Descendants("song"))
{
string fileName = s.Attribute("name").Value;
string uri = s.Attribute("file").Value;
Console.WriteLine("Downloading {0}", fileName);
if(uri.EndsWith(".mp3") && !fileName.EndsWith(".mp3"
))
fileName = string.Concat(fileName, ".mp3");
fileName = string.Concat(@"C:\Temp\music\", fileName
);
if( !Directory.Exists(@"C:\Temp\music") ) Directory.
CreateDirectory(@"C:\Temp\music");
wc.Headers.Clear();
wc.Headers.Add("User-Agent", "Windows-Media-Player/
11.0.5721.5145");
wc.DownloadFile(uri, fileName);
}
Console.WriteLine("All done");
}
}
It's not as heavy as VS; but very handy to test out code snippets. For an
exmple download music from wenxuecity.com. Once you figured out the
playListXml (either view source or sniff), a few lines code as follows run
great in LinqPad:
void Main()
{
string playListUrl = @"http://space.wenxuecity.com/media/1292261551.xml";
using(WebClient wc = new WebClient())
{
wc.Headers.Add("User-Agent", "Mozilla/4.0 (compatible; MSIE
8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .
NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; MS-RTC LM 8; .NET4.0C; .NET4.0E)"
);
string xmlContent = wc.DownloadString(playListUrl);
XDocument doc = XDocument.Parse(xmlContent);
foreach(var s in doc.Descendants("song"))
{
string fileName = s.Attribute("name").Value;
string uri = s.Attribute("file").Value;
Console.WriteLine("Downloading {0}", fileName);
if(uri.EndsWith(".mp3") && !fileName.EndsWith(".mp3"
))
fileName = string.Concat(fileName, ".mp3");
fileName = string.Concat(@"C:\Temp\music\", fileName
);
if( !Directory.Exists(@"C:\Temp\music") ) Directory.
CreateDirectory(@"C:\Temp\music");
wc.Headers.Clear();
wc.Headers.Add("User-Agent", "Windows-Media-Player/
11.0.5721.5145");
wc.DownloadFile(uri, fileName);
}
Console.WriteLine("All done");
}
}