我有很多文件类型:pdf,tiff,jpeg,bmp.我的问题是如何更改文件扩展名?我试过这个:
my file= c:/my documents/my images/cars/a.jpg;
string extension = Path.GetExtension(myffile);
myfile.replace(extension,".Jpeg");
Run Code Online (Sandbox Code Playgroud)
无论它是什么类型的文件,我指定的格式必须是文件名.但它不起作用.我从浏览器中获取文件路径c:\..\..\a.jpg,文件格式为a.jpeg.所以,当我尝试删除它时,它会给我一个错误:Cannot find the file on specified path'.所以,我认为它与文件扩展名不匹配有关.所以,我试图转换.jpg到.jpeg并删除文件即可.
我想删除一个包含文件的文件夹和一个包含文件的子文件夹.我已经使用了所有东西,但它对我不起作用.我在我的web应用程序asp.net中使用以下函数:
var dir = new DirectoryInfo(folder_path);
dir.Delete(true);
Run Code Online (Sandbox Code Playgroud)
有时它删除文件夹,有时则不删除.如果子文件夹包含文件,它只删除文件,而不删除文件夹.
在c#中重命名文件:
File.Move(source,Destination);
File.Delete(source);
Run Code Online (Sandbox Code Playgroud)
它成功执行,但是当我再次尝试重命名文件时,系统会给出以下异常: 进程无法访问该文件,因为它正由另一个进程使用. 我无法发现它在哪里使用?当我进一步调试错误时,它显示我的类名是在w3wp.exe的过程中,这是IIS.我接下来该怎么办?越来越
foreach (string folder in folder)
{
FileSystemItem item = new FileSystemItem();
DirectoryInfo di = new DirectoryInfo(folder);
item.Name = di.Name;
item.FullName = di.FullName;
item.Path = path + "\\" + item.Name;
item.CreatedDate = di.CreationTime;
item.IsFolder = true;
item.Extension = "folder";
listFolder.Add(item);
}
docList = CreatXmllist(listFolder);
return docList
Run Code Online (Sandbox Code Playgroud)
这是我如何获取文件夹列表,然后它返回到xml.然后在文件夹中我点击它时获取文件
现在来获取图像:这是代码
public xml (string path, List<l> one)
{
List<T> tt = new List<T>();
List<T> SessionList = new List<T>();
string[] files = Directory.GetFiles(HttpContext.Current.Request.PhysicalApplicationPath + path);
foreach (string file in …Run Code Online (Sandbox Code Playgroud) 我有ac#函数用于生成缩略图图像,这些图像显示在网页上,即ASP.net所以我如何编程调用这个后端函数,让我们每天在16:00或3:00说.
我有一个像这样的字符串string strings=" black door,white door,red door "
现在我想把这个字符串放入数组.
我使用split myarray = strings.split(',')然后数组看起来像这样:black,door,white,door,red,door.
我想在每次出现逗号之后将字符串放入数组中.我想在数组中这样:
black door,white door,red door.
当我想用文件名填充数组时,我遇到了问题.
代码是:
string [] arrays= {};
String sdira= "path of the directory";
foreach (string d in Directory.GetDirectories(sdira))
{
foreach (string f in Directory.GetFiles(d, "*.*"))`enter code here`
{
int j = 0;
array[j++] = path.getfiles(f);
}
}
Run Code Online (Sandbox Code Playgroud)
当我遍历数组时,数组不包含任何东西:(那么如何在这种情况下填充数组?或任何更好的解决方案:)
我有一个 string path = c:\inetpub\wwwrroot\images\pdf\admission.pdf
我正在使用这个
path = path.LastIndexOf("\\").ToString();
path = path.Substring(path.LastIndexOf("/") + 1);
Run Code Online (Sandbox Code Playgroud)
我想得到:
c:\inetpub\wwwrroot\images\pdf
c:\inetpub\wwwrroot\images\pdf\admission.pdf
Run Code Online (Sandbox Code Playgroud)
现在我想从这里得到录取.pdf string path我该怎么办?
我发布了我的网站.在vs 2008中使用发布网站.现在我想更新单个文件.所以我需要重新编译整个网站并再次将其上传到服务器,或者我只是发布这个单个文件并将其上传到服务器.
如果我可以编译单个文件然后如何做,还有如何更新到服务器?
我写了一个小代码,如果一个zip文件超过5小时(300薄荷),检查时间例程,然后必须删除该文件.我有这个代码.但它没有删除任何文件.
string[] zipfiles = Directory.GetFiles("D:\\images\\zipFiles\\", "*.zip*");
foreach (string zip in zipfiles)
{
FileInfo zipinfo = new FileInfo(zip);
string t = zipinfo.CreationTime.ToString();
TimeSpan span = DateTime.Now - zipinfo.CreationTime;
int k =0;
k = span.Minutes;
if (k > 300)
{
zipinfo.Delete();
}
else
{
}
}
Run Code Online (Sandbox Code Playgroud) 我在另一个类中调用此zip_threading类. string a = zip_threading(?,?)但问题是,当我调用这个类时,我如何传递参数值:String [] files,bool IsOriginal.我在这个类后台工作者线程中使用过,所以真正的问题是将值传递给这个类,然后在make_zip_file类中处理完成后返回一个值.
public class zip_threading
{
public string[] files { get; set; } // to be recieved by the zip method as zip file names.
public int number;
public string return_path;
public bool IsOriginal { get; set; } // to be recieved by the zip method as boolean true or fales
public static BackgroundWorker bgw1 = new BackgroundWorker(); // make a background worker object.
public void bgw1_RunWorkerCompleted(Object sender, RunWorkerCompletedEventArgs e)
{
make_zip_file mzf1 …Run Code Online (Sandbox Code Playgroud) 我想把一个字符串放入数组,假设我有一个字符串,string a = "dog cat horse mouse"所以我想把这个字符串放入一个数组,就像它出现在字符串中的单独工作.
string array [0]=dog
string array [1]=cat
string array [2]=horse
string array [3]=mouse
Run Code Online (Sandbox Code Playgroud)
或者像这样
string array= {"dog", "Cat", "mouse", "horse"};
Run Code Online (Sandbox Code Playgroud)
我想在数组中这样,所以:)
我想使用数组从访问数据库中删除多个记录.该数组是从文件名动态加载的.
然后我查询数据库,看看数据库列值是否与数组值匹配,如果没有则删除它,如果匹配则不删除它.
问题是:以下是删除所有记录的代码,与条件中的位置无关.
arrays = Directory.GetFiles(sdira, "*", SearchOption.AllDirectories).Select(x => Path.GetFileName(x)).ToArray();
fnames.AddRange(arrays);
here I have use also for loop but that also didnt help me out :( like for(int u = 0; u < arrays.length; u++) { oledbcommand sqlcmd = new oledbcommand ("delete from table1 where name not in ("'+arrays[u]+"')",sqlconnection);
I am using this one currently foreach(string name in arrays)
{
OleDbCommand sqlcmd = new OleDbCommand("delete from table1 where name not in ('" + name + "')", sqlconnection);
sqlcmd.ExecuteNonQuery(); }`
Run Code Online (Sandbox Code Playgroud)