请问大家,我用这种来获取文件源 System.Net.FileWebRequest q = (System.Net.FileWebRequest)System.Net.FileWebRequest.Create(filepath);
System.Net.FileWebResponse p = (System.Net.FileWebResponse)q.GetResponse();然后应该怎么写来获取这个文件的大小呢???用这种方式是否也可以来改变整张图片的大小???
System.Net.FileWebResponse p = (System.Net.FileWebResponse)q.GetResponse();然后应该怎么写来获取这个文件的大小呢???用这种方式是否也可以来改变整张图片的大小???
解决方案 »
- Asp.net推送推荐歌曲
- 得到一个url地址,怎样生成一个html的树形图来呢
- 如何在自定义的IHttpHandler中使用默认的HttpHandler方法?
- 编写的组件类 只能给指定的人使用,如何许可和授权??
- 请教高手,关于IP的问题
- 用System.Diagnostics.Process.Start()调用默认的程序打开文件,怎么在生成网页后,就不能弹出打开文件
- 请教一个datagrid的问题。
- xml ,AppendChild ,发生错误:要插入的节点出自不同的文档上下文。
- 可以在vs2005调试运行(ctrl+F5),可是输入ip后运行就出错,大家帮我看看吧
- 关于CrystalReportViewer Toobar的问题?
- [最后的10分],挑战信誉分“最低点”,肯定值看。眼前36,我绝对不换马甲,请看。
- 这是用的什么数据库?在线急等
double fileLength = p.ContentLength;
楼主试试,就是流的长度
好像得到的是字节数
// This example creates or opens a text file and stores a string in it.
// Both the file and the string are passed by the user.
// Note. For this program to work, the folder containing the test file
// must be shared, with its permissions set to allow write access. using System.Net;
using System;
using System.IO;
using System.Text;namespace Mssc.PluggableProtocols.File
{
class TestGetRequestStream
{
private static FileWebRequest myFileWebRequest; private static void showUsage()
{
Console.WriteLine("\nPlease enter file name and timeout :");
Console.WriteLine("Usage: cs_getrequeststream <systemname>/<sharedfoldername>/<filename> timeout");
Console.WriteLine("Example: cs_getrequeststream ngetrequestrtream() ndpue/temp/hello.txt 1000");
Console.WriteLine("Small time-out values (for example, 3 or less) cause a time-out exception.");
} private static void makeFileRequest(string fileName, int timeout)
{
try
{
// Create a Uri object.
Uri myUrl=new Uri("file://" + fileName);
// Create a FileWebRequest object.
myFileWebRequest = (FileWebRequest)WebRequest.CreateDefault(myUrl);
// Set the time-out to the value selected by the user.
myFileWebRequest.Timeout = timeout;
// Set the Method property to POST
myFileWebRequest.Method="POST";
}
catch(WebException e)
{
Console.WriteLine("WebException: "+e.Message);
}
catch(UriFormatException e)
{
Console.WriteLine("UriFormatWebException: "+e.Message);
}
} private static void writeToFile()
{
try
{
// Enter the string to write to the file.
Console.WriteLine("Enter the string you want to write:");
string userInput = Console.ReadLine();
// Convert the string to a byte array.
ASCIIEncoding encoder = new ASCIIEncoding();
byte[] byteArray = encoder.GetBytes(userInput);
// Set the ContentLength property.
myFileWebRequest.ContentLength=byteArray.Length;
string contentLength = myFileWebRequest.ContentLength.ToString();
Console.WriteLine("\nThe content length is {0}.", contentLength);
// Get the file stream handler to write to the file.
Stream readStream=myFileWebRequest.GetRequestStream(); // Write to the file stream.
// Note. For this to work, the file must be accessible
// on the network. This can be accomplished by setting the property
// sharing of the folder containg the file.
// FileWebRequest.Credentials property cannot be used for this purpose.
readStream.Write(byteArray,0,userInput.Length); Console.WriteLine("\nThe String you entered was successfully written to the file."); readStream.Close(); }
catch(WebException e)
{
Console.WriteLine("The WebException: "+e.Message);
}
catch(UriFormatException e)
{
Console.WriteLine("The UriFormatWebException: "+e.Message);
}
} public static void Main(String[] args)
{
if (args.Length < 2)
showUsage();
else
{
makeFileRequest(args[0], int.Parse(args[1]));
writeToFile();
}
}
}
}