PDA

View Full Version : آموزش: کلاسی برای مدیریت فایل های وب سایت به صورت اجکسی در Asp.net .(کد باز ، رایگان)



aminghaderi
دوشنبه 25 اردیبهشت 1391, 10:18 صبح
سلام خدمت همه دوستان و همکاران عزیز .
در همین تالار کلاس هایی رو دوستان برای کار با فایل ها در قالب فایل dll اماده کردن بودند و حالا من یه قدم بالا تر می روم و کل کد های اون رو براتون می زارم ، البته کار من نیست کار BinaryIntellect Consulting هست.
خوب ولی به هر حال تلاش های من هم برای پیدا کردن اون و نشر اون هست و این کار من هم رایگان نیست؟!
هزینه اون انتشار شما به بقیه برنامه نویس های asp.net هست ایرانی و غیر ایرانی فرقی نداره.:چشمک:

فایل اصلی ajaxfilemanager :
87054
برای استفاده به ajaxToolkit نیاز هست.
اجکس با استفاد از page method هم صورت گرفته.
اگر AjaxToolkit ندارید مشکلی نیست بدون اون شما قادر به تست برنامه هستید ، بروی vs من هم AjaxToolkit نصب نیست.


امیدورام مفید باشه.

aminghaderi
دوشنبه 25 اردیبهشت 1391, 10:23 صبح
اما کلاسی که برای کار با فایل ها وب به صورت غیر اجکسی می توان کار کرد و البته کلاس اصلی :

1) FileSystemItem
2) FileSystemManager


public class FileSystemItem
{
private string strName;
private string strFullName;

private DateTime dtCreationDate;
private DateTime dtLastAccessDate;
private DateTime dtLastWriteDate;

private bool blnIsFolder;

private long lngSize;
private long lngFileCount;
private long lngSubFolderCount;

public string Name
{
get { return strName; }
set { strName = value; }
}

public string FullName
{
get { return strFullName; }
set { strFullName = value; }
}

public DateTime CreationDate
{
get { return dtCreationDate; }
set { dtCreationDate = value; }
}

public bool IsFolder
{
get { return blnIsFolder; }
set { blnIsFolder = value; }
}

public long Size
{
get{return lngSize;}
set{lngSize = value;}
}

public DateTime LastAccessDate
{
get{return dtLastAccessDate;}
set{dtLastAccessDate = value;}
}

public DateTime LastWriteDate
{
get{return dtLastWriteDate;}
set{dtLastWriteDate = value;}
}

public long FileCount
{
get{return lngFileCount;}
set{lngFileCount = value;}
}

public long SubFolderCount
{
get{return lngSubFolderCount;}
set{lngSubFolderCount = value;}
}
}






public class FileSystemManager
{
private static string strRootFolder;

static FileSystemManager()
{
strRootFolder = HttpContext.Current.Request.PhysicalApplicationPat h;
strRootFolder = strRootFolder.Substring(0, strRootFolder.LastIndexOf(@"\"));
}

public static string GetRootPath()
{
return strRootFolder;
}

public static void SetRootPath(string path)
{
strRootFolder = path;
}

public static List<FileSystemItem> GetItems()
{
return GetItems(strRootFolder);
}

public static List<FileSystemItem> GetItems(string path)
{
string[] folders = Directory.GetDirectories(path);
string[] files = Directory.GetFiles(path);
List<FileSystemItem> list = new List<FileSystemItem>();
foreach (string s in folders)
{
FileSystemItem item = new FileSystemItem();
DirectoryInfo di = new DirectoryInfo(s);
item.Name = di.Name;
item.FullName = di.FullName;
item.CreationDate = di.CreationTime;
item.IsFolder = true;
list.Add(item);
}
foreach (string s in files)
{
FileSystemItem item = new FileSystemItem();
FileInfo fi = new FileInfo(s);
item.Name = fi.Name;
item.FullName = fi.FullName;
item.CreationDate = fi.CreationTime;
item.IsFolder = true;
item.Size = fi.Length;
list.Add(item);
}

if (path.ToLower() != strRootFolder.ToLower())
{
FileSystemItem topitem = new FileSystemItem();
DirectoryInfo topdi = new DirectoryInfo(path).Parent;
topitem.Name = "[Parent]";
topitem.FullName = topdi.FullName;
list.Insert(0, topitem);

FileSystemItem rootitem = new FileSystemItem();
DirectoryInfo rootdi = new DirectoryInfo(strRootFolder);
rootitem.Name = "[Root]";
rootitem.FullName = rootdi.FullName;
list.Insert(0, rootitem);

}
return list;
}

public static void CreateFolder(string name, string parentName)
{
DirectoryInfo di = new DirectoryInfo(parentName);
di.CreateSubdirectory(name);
}

public static void DeleteFolder(string path)
{
Directory.Delete(path);
}

public static void MoveFolder(string oldPath, string newPath)
{
Directory.Move(oldPath, newPath);
}

public static void CreateFile(string filename, string path)
{
FileStream fs = File.Create(path + "\\" + filename);
fs.Close();
}

public static void CreateFile(string filename, string path, byte[] contents)
{
FileStream fs = File.Create(path + "\\" + filename);
fs.Write(contents, 0, contents.Length);
fs.Close();
}

public static void DeleteFile(string path)
{
File.Delete(path);
}

public static void MoveFile(string oldPath, string newPath)
{
File.Move(oldPath, newPath);
}

public static FileSystemItem GetItemInfo(string path)
{
FileSystemItem item = new FileSystemItem();
if (Directory.Exists(path))
{
DirectoryInfo di = new DirectoryInfo(path);
item.Name = di.Name;
item.FullName = di.FullName;
item.CreationDate = di.CreationTime;
item.IsFolder = true;
item.LastAccessDate = di.LastAccessTime;
item.LastWriteDate = di.LastWriteTime;
item.FileCount = di.GetFiles().Length;
item.SubFolderCount = di.GetDirectories().Length;
}
else
{
FileInfo fi = new FileInfo(path);
item.Name = fi.Name;
item.FullName = fi.FullName;
item.CreationDate = fi.CreationTime;
item.LastAccessDate = fi.LastAccessTime;
item.LastWriteDate = fi.LastWriteTime;
item.IsFolder = false;
item.Size = fi.Length;
}
return item;
}

public static void CopyFolder(string source, string destination)
{
String[] files;
if (destination[destination.Length - 1] != Path.DirectorySeparatorChar)
destination += Path.DirectorySeparatorChar;
if (!Directory.Exists(destination)) Directory.CreateDirectory(destination);
files = Directory.GetFileSystemEntries(source);
foreach (string element in files)
{
if (Directory.Exists(element))
CopyFolder(element, destination + Path.GetFileName(element));
else
File.Copy(element, destination + Path.GetFileName(element), true);
}
}
}

aminghaderi
دوشنبه 25 اردیبهشت 1391, 10:37 صبح
از مزیت های این برنامه نوشتن کد های استاندارد و نمایش قابلت Asp.net هست .
گر چه خود برنامه اینقدر حرفه ای و شیوا نوشته شده که نیازی به توضیحات اضافی نداره و خود کد ها با برنامه نویس صحبت می کنند ولی خیلی دوست دارم کاملا کلاس رو براتون شرح بدم قدم به قدم و جز به جز ولی وقتش متاسفانه نیست و اگر بگم بعدا این کار رو می کنم ، دروغ گفتم چون مشغله من تمامی نداره ، شاید خودم تمام بشم که اون ها هم تمام شوند:ناراحت:.
از این رو از دوستانی که وقتشان آزاد تر هست و مایل هستند برای افزایش بار علمی جامعه نرم افزار گام برداند می خام تا این تاپیک رو ادامه دهند.
اما اگر دوستان سوالی داشند بفرمایند تا در وسع خودم پاسخ دهم.


با تشکر.